Scopes of Macro Variables |
While developing your macros, you might find it useful to write all or part of the contents of the global and local symbol tables to the SAS log. To do so, use the %PUT statement with one of the following options:
_ALL_ |
describes all currently defined macro variables, regardless of scope. This output includes user-defined global and local variables as well as automatic macro variables. Scopes are listed in the order of innermost to outermost. |
_AUTOMATIC_ |
describes all automatic macro variables. The scope is listed as AUTOMATIC. All automatic macro variables are global except SYSPBUFF. See Macro Language Elements and Automatic Macro Variables for more information about specific automatic macro variables. |
_GLOBAL_ |
describes all global macro variables that were not created by the macro processor. The scope is listed as GLOBAL. Automatic macro variables are not listed. |
_LOCAL_ |
describes user-defined local macro variables defined within the currently executing macro. The scope is listed as the name of the macro in which the macro variable is defined. |
_USER_ |
describes all user-defined 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. |
For example, consider the following program:
%let origin=North America; %macro dogs(type=); data _null_; set all_dogs; where dogtype="&type" and dogorig="&origin"; put breed " is for &type."; run; %put _user_; %mend dogs; %dogs(type=work)
The %PUT statement preceding the %MEND statement writes to the SAS log the scopes, names, and values of all user-generated macro variables:
DOGS TYPE work GLOBAL ORIGIN North America
Because TYPE is a macro parameter, TYPE is local to the macro DOGS, with value work . Because ORIGIN is defined in open code, it is global.
Copyright © 2009 by SAS Institute Inc., Cary, NC, USA. All rights reserved.