|Restriction:||Allowed in macro definitions or open code|
|Example 1: Displaying Text|
|Example 2: Displaying Automatic Variables|
|Example 3: Displaying User-Generated Variables|
|Example 4: Displaying Local Variables|
|%PUT <text | _ALL_ | _AUTOMATIC_ | _GLOBAL_ | _LOCAL_ | _USER_>;|
is text or a text expression that is written to the SAS log. If text is longer than the current line size, the remainder of the text appears on the next line. The %PUT statement removes leading and trailing blanks from text unless you use a macro quoting function.
When you use the %PUT statement to list macro variable descriptions, the %PUT statement includes only the macro variables that exist at the time the statement executes. The description contains the macro variable's scope, name, and value. Macro variables with null values show only the scope and name of the variable. Characters in values that have been quoted with macro quoting functions remain quoted. Values that are too long for the current line size wrap to the next line or lines. Macro variables are listed in order from the current local macro variables outward to the global macro variables.
Note: Within a particular scope, macro variables might appear in any order, and the order might change in different executions of the %PUT statement or different SAS sessions. Do not write code that depends on locating a variable in a particular position in the list.
The %PUT statement displays text in different colors to generate messages that look like ERROR, NOTE, and WARNING messages generated by SAS. To display text in different colors, the first word in the %PUT statement must be ERROR, NOTE, or WARNING, followed immediately by a colon or a hyphen. You might also use the national-language equivalents of these words. When you use a hyphen, the ERROR, NOTE, or WARNING word is blanked out.
Note: If you use the %PUT statement and the last message text that was generated by the SYSWARNINGTEXT and SYSERRORTEXT automatic macro variables contained an & or %, you must use the %SUPERQ macro quoting function. For more information, see SYSERRORTEXT Automatic Macro Variable and SYSWARNINGTEXT Automatic Macro Variable.
%put One line of text.; %put %str(Use a semicolon(;) to end a SAS statement.); %put %str(Enter the student%'s address.);
The result in the SAS log (depending on the products installed at your site) lists the scope, name, and value of each automatic variable:
AUTOMATIC SYSBUFFR AUTOMATIC SYSCMD AUTOMATIC SYSDATE 21JUN97 AUTOMATIC SYSDAY Wednesday AUTOMATIC SYSDEVIC AUTOMATIC SYSDSN _NULL_ AUTOMATIC SYSENV FORE AUTOMATIC SYSERR 0 AUTOMATIC SYSFILRC 0 AUTOMATIC SYSINDEX 0 AUTOMATIC SYSINFO 0
%macro myprint(name); proc print data=&name; title "Listing of &name on &sysdate"; footnote "&foot"; run; %put _user_; %mend myprint; %let foot=Preliminary Data; %myprint(consumer)
%macro analyze(name,vars); proc freq data=&name; tables &vars; run; %put FIRST LIST:; %put _local_; %let firstvar=%scan(&vars,1); proc print data=&name; where &firstvar ne .; run; %put SECOND LIST:; %put _local_; %mend analyze; %analyze(consumer,car house stereo)
FIRST LIST: ANALYZE NAME consumer ANALYZE VARS car house stereo SECOND LIST: ANALYZE NAME consumer ANALYZE VARS car house stereo ANALYZE FIRSTVAR car