%PUT Statement
Writes text or macro variable information to the SAS log.
Type: Macro statement
Restriction: Allowed in macro definitions or open code
Syntax
%PUT <text | _ALL_ | _AUTOMATIC_ | _GLOBAL_ | _LOCAL_ | _READONLY_
| _USER_ | _WRITABLE_>;
Required Arguments
no argument
places a blank line in the SAS log.
text
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.
_ALL_
lists the values of all user-generated and automatic macro variables.
_AUTOMATIC_
lists the values of automatic macro variables. The automatic variables listed depend
on the SAS products installed at your site and on your operating system. The scope is
identified as AUTOMATIC.
_GLOBAL_
lists user-generated global macro variables. The scope is identified as GLOBAL.
_LOCAL_
lists user-generated local macro variables. The scope is the name of the currently
executing macro.
_READONLY_
lists all user-defined read-only macro variables, regardless of scope. The scope is
either GLOBAL, for global macro variables, or the name of the macro in which the
macro variable is defined.
_USER_
lists user-generated global and local macro variables. The scope is identified either as
GLOBAL, or as the name of the macro in which the macro variable is defined.
_WRITABLE_
lists all user-defined read and write macro variables, regardless of scope. The scope
is either GLOBAL, for global macro variables, or the name of the macro in which
the macro variable is defined.
Details
When you use the %PUT statement to list macro variable descriptions, the %PUT
statement includes only the macro variables that exist when statement executes. The
description contains the macro variable's scope, name, and value. Macro variables with
332 Chapter 19 Macro Statements
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: Prior to SAS 9.4, within a particular scope, macro variables might appear in any
order. And the order might change in different executions of the %PUT statement or
in different SAS sessions. But beginning in SAS 9.4, the variables are always listed
alphabetically. However, automatic macro variables created in a SAS session might
differ depending on which SAS products are installed and the platform on which
SAS is running. Users are advised to refrain from writing code that depends on them
appearing in a predictable order.
The following figure shows the relationship of these terms.
Figure 19.1 %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 (all uppercase letters), followed immediately by a colon or a hyphen. You
might also use the national-language equivalents of these words. Using a hyphen (-)
following the ERROR, NOTE, or WARNING keyword causes the text of the %PUT
statement to be a continuation of the previous ERROR, NOTE, or WARNING message,
respectively. 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” on page 211 and
“SYSWARNINGTEXT Automatic Macro Variable” on page 234.
T I P If you place an equal sign between the ampersand and the macro variable name
of a direct macro variable reference, the macro variable's name is displayed in the log
along with the macro variable's value.
%let x=1;
%put &=x;
X=1;
%PUT Statement 333
Examples
Example 1: Displaying Text
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.
Example 2: Displaying Automatic Variables
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
Example 3: Displaying User-Generated Variables
This example lists the user-generated macro variables in all scopes.
%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.
334 Chapter 19 Macro Statements
%put _user_;
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
Example 4: Displaying Local Variables
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 that is 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
%RETURN Statement
Execution causes normal termination of the currently executing macro.
Type: Macro Statement
Restriction: Valid only in a macro definition
Syntax
%RETURN;
Details
The %RETURN macro causes normal termination of the currently executing macro.
%RETURN Statement 335
Example: Using %RETURN Statement
In this example, if the error variable is set to 1, then the macro will stop executing and
the DATA step will not execute.
%macro checkit(error);
%if &error = 1 %then %return;
data a;
x=1;
run;
%mend checkit;
%checkit(0)
%checkit(1)
%SYMDEL Statement
Deletes the specified variable or variables from the macro global symbol table.
Type: Macro Statement
Syntax
%SYMDEL macro-variable(s)</option> ;
Required Arguments
macro-variable(s)
is the name of one or more macro variables or a text expression that generates one or
more macro variable names. You cannot use a SAS variable list or a macro
expression that generates a SAS variable list in a %SYMDEL statement.
option
NOWARN
suppresses the warning message when an attempt is made to delete a non-existent
macro variable.
Details
%SYMDEL statement issues a warning when an attempt is made to delete a non-existent
macro variable. To suppress this message, use the NOWARN option.
%SYSCALL Statement
Invokes a SAS call routine.
Type: Macro statement
Restriction: Allowed in macro definitions or in open code
See: “%SYSFUNC and %QSYSFUNC Functions” on page 283
Syntax
%SYSCALL call-routine< (call-routine-argument(s))>;
336 Chapter 19 Macro Statements
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset