|Scopes of Macro Variables|
The following figure illustrates the global symbol table during execution of the following program:
%let county=Clark; %macro concat; data _null_; length longname $20; longname="&county"||" County"; put longname; run; %mend concat; %concat
Calling the macro CONCAT produces the following statements:
The PUT statement writes the following to the SAS log:
Global macro variables include the following:
all automatic macro variables except SYSPBUFF. See Automatic Macro Variables for more information about SYSPBUFF and other automatic macro variables.
macro variables created outside of any macro.
macro variables created in %GLOBAL statements. See Creating Global Macro Variables for more information about the %GLOBAL statement.
most macro variables created by the CALL SYMPUT routine. See Special Cases of Scope with the CALL SYMPUT Routine for more information about the CALL SYMPUT routine.
You can create global macro variables any time during a SAS session or job. Except for some automatic macro variables, you can change the values of global macro variables any time during a SAS session or job.
In most cases, once you define a global macro variable, its value is available to you anywhere in the SAS session or job and can be changed anywhere. So, a macro variable referenced inside a macro definition is global if a global macro variable already exists by the same name (assuming that the variable is not specifically defined as local with the %LOCAL statement or in a parameter list). The new macro variable definition simply updates the existing global one. The following are exceptions that prevent you from referencing the value of a global macro variable:
when a macro variable exists both in the global symbol table and in the local symbol table, you cannot reference the global value from within the macro that contains the local macro variable. In this case, the macro processor finds the local value first and uses it instead of the global value.
if you create a macro variable in the DATA step with the SYMPUT routine, you cannot reference the value with an ampersand until the program reaches a step boundary. See Macro Processing for more information about macro processing and step boundaries.
You can use the %SYMGLOBL function to indicate whether an existing macro variable resides in the global symbol table. See the %SYMGLOBL Function for more detailed information.