Local macro variables are defined within an individual
macro. Each macro that you invoke creates its own local symbol table.
Local macro variables exist only as long as a particular macro executes.
When the macro stops executing, all local macro variables for that
macro cease to exist.
The following figure
illustrates the local symbol table during the execution of the following
program.
%macro holinfo(day,date);
%let holiday=Christmas;
%put *** Inside macro: ***;
%put *** &holiday occurs on &day, &date, 2002. ***;
%mend holinfo;
%holinfo(Wednesday,12/25)
%put *** Outside macro: ***;
%put *** &holiday occurs on &day, &date, 2002. ***;
The %PUT statements
write the following to the SAS log:
*** Inside macro: ***
*** Christmas occurs on Wednesday, 12/25, 2002. ***
*** Outside macro: ***
WARNING: Apparent symbolic reference HOLIDAY not resolved.
WARNING: Apparent symbolic reference DAY not resolved.
WARNING: Apparent symbolic reference DATE not resolved.
*** &holiday occurs on &day, &date, 2002. ***
As you can see from
the log, the local macro variables DAY, DATE, and HOLIDAY resolve
inside the macro, but outside the macro that they do not exist and
therefore do not resolve.
A macro's local symbol
table is empty until the macro creates at least one macro variable.
A local symbol table can be created by any of the following:
-
the presence of one or more macro
parameters
-
-
macro statements that define macro
variables, such as %LET and the iterative %DO statement (if the variable
does not already exist globally or a %GLOBAL statement is not used)
When you invoke one
macro inside another, you create nested scopes. Because you can have
any number of levels of nested macros, your programs can contain any
number of levels of nested scopes.
You can use the %SYMLOCAL
function to indicate whether an existing macro variable resides in
an enclosing local symbol table. See the
%SYMLOCAL Function for more detailed information.