• all automatic macro variables except SYSPBUFF. For more information about
SYSPBUFF and other automatic macro variables, see “Automatic Macro Variables”
on page 167.
• macro variables created outside of any macro.
• macro variables created in %GLOBAL statements. For more information about the
%GLOBAL statement, see “Creating Global Macro Variables” on page 63.
• most macro variables created by the CALL SYMPUT routine. For more information
about the CALL SYMPUT routine, see “Special Cases of Scope with the CALL
SYMPUT Routine” on page 65.
You can create global macro variables anytime during a SAS session or job. Except for
some automatic macro variables, you can change the values of global macro variables
anytime 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. This action assumes 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. For more information about macro processing and step boundaries, see
Chapter 4, “Macro Processing,” on page 39.
You can create a read-only global macro variable and assign a specified value to it using
the READONLY option in a %GLOBAL statement. Existing macro variables cannot be
made read-only. The value of the variable cannot be changed, and the variable cannot be
deleted. All read-only macro variables persist until the scope in which they exist is
deleted. For more information, see “%GLOBAL Statement” on page 314.
You can use the %SYMGLOBL function to indicate whether an existing macro variable
resides in the global symbol table. For more information, see “%SYMGLOBL Function”
on page 279.
Local Macro Variables
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 code illustrates the local symbol table during the execution of the
following program.
%macro holinfo(day,date);
%let holiday=Christmas;
%put *** Inside macro: ***;
Local Macro Variables 51