|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_>;|
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 may appear in any order, and the
order may 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.
%PUT Arguments by Type and Scope shows the relationship of these terms.
%PUT Arguments by Type and Scope
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 may also use the national-language equivalents of these words. When you use a hyphen, the ERROR, NOTE, or WARNING word is blanked out.
The following statements illustrate using the %PUT statement to write text to the SAS log:
%put One line of text.; %put %str(Use a semicolon(;) to end a SAS statement.); %put %str(Enter the student%'s address.);
When you submit these statements, these lines appear in the SAS log:
One line of text. Use a semicolon(;) to end a SAS statement. Enter the student's address.
To display all automatic variables, submit
%put _automatic_;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
This example lists the user-generated macro variables in all referencing environments.
%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)
The %PUT statement writes these lines to the SAS log:
MYPRINT NAME consumer GLOBAL FOOT Preliminary Data
Notice that SYSDATE does not appear because it is an automatic macro variable.
To display the user-generated variables after macro MYPRINT finishes, submit another %PUT statement.
The result in the SAS log does not list the macro variable NAME because it was local to MYPRINT and ceased to exist when MYPRINT finished execution.
GLOBAL FOOT Preliminary Data
This example displays the macro variables that are local to macro ANALYZE.
%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)
In the result, printed in the SAS log, the macro variable FIRSTVAR, which was created after the first %PUT _LOCAL_ statement, appears only in the second list.
FIRST LIST: ANALYZE NAME consumer ANALYZE VARS car house stereo SECOND LIST: ANALYZE NAME consumer ANALYZE VARS car house stereo ANALYZE FIRSTVAR car
Top of Page
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.