BookmarkSubscribeRSS Feed

%PUT macro statement

Started ‎07-05-2018 by
Modified ‎07-06-2018 by
Views 3,598

The %PUT macro statement or %PUT statement is a SAS macro language statement that displays text or the values of macro variables in the SAS log.

 

Syntax

%PUT text ;

or

%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.
    • _ALL_
    • _AUTOMATIC_
    • _GLOBAL_
    • _LOCAL_
    • _USER_
    • _READONLY_ (Only in SAS 9.4)
    • _WRITABLE_ (Only in SAS 9.4)

Usage

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 proceeded by an ampersand symbol (&). If both the macro variable name and value are to be displayed in the SAS log then proceeding 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.

 

Further reading

  • SAS Macro Language: Reference: %PUT Statement - Versions: 9.2, 9.3, 9.4

This article was originally posted by Cameron on sasCommunity.org.

Version history
Last update:
‎07-06-2018 03:44 PM
Updated by:
Contributors

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Free course: Data Literacy Essentials

Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning  and boost your career prospects.

Get Started

Article Labels
Article Tags