As the first step in the decommissioning of sasCommunity.org the site has been converted to read-only mode.
Here are some tips for How to share your SAS knowledge with your professional network.
%PUT macro statement
As part of the decommissioning effort for sasCommunity.org this article/tip has been migrated to communities.sas.com.
The new home for this article/tip is %PUT macro statement (https://communities.sas.com/t5/SAS-Communities-Library/PUT-macro-statement/ta-p/475836)
- This is a work in progress. You can contribute to this article.
- %PUT text ;
- %PUT type of macro variable ;
- text is the text to be put into the SAS log. The text can include macro variables, macro quoting functions and escaped characters. However, leading and trailing blank spaces surrounding the text are ignored. If text is omitted then a blank line is put in the SAS log.
- type of macro variable can be one of the following identifiers.
- _READONLY_ (Only in SAS 9.4)
- _WRITABLE_ (Only in SAS 9.4)
The %PUT macro statement can be used in open code. It is often used when debugging a program to reveal the values contained in macro variables or to confirm that a program has reached a particular point in processing.
If some or all of the text is contained in another macro variable then that macro variable name needs to be preceeded by an ampersand symbol (&). If both the macro variable name and value are to be displayed in the SAS log then preceeding macro variable name with both an ampersand symbol and an equals sign (&=) produces macro_name = value in the log.
Also, a macro variable name needs to be followed by a period (.) if there is no trailing space or other character that identifies the starts of a new token. This is so the macro language parser can tell where the macro variable name ends, so it will not misinterpret trailing text as part of the macro variable name. The trailing period at the end of any macro variable name is considered part of the name. If a period needs to be displayed immediately after the the text contained in the macro variable then the the macro variable name needs to be immediately followed by two (2) periods, rather than one.
Various quoting and unquoting macro functions can also be used in the text to hide characters from the parser (or tokenizer), so they can be printed to the log as text.
Not quite what you are looking for? There are several other statements and functions that have a similar functionality to the %PUT macro statement:
- %LET macro statement assigns text to a macro variable.
- PUTLOG statement puts text to the SAS log.
- PUT function outputs an expression as a character string.
- INPUT function outputs an expression as a numeric value.
- PUT statement outputs text to a file within a DATA step.
- OUTPUT statement writes variable values to a dataset within a DATA step.
- PUT keyword