Two rules control where CALL SYMPUT creates its variables:
1. CALL SYMPUT creates the macro variable in the current symbol table available
while the DATA step is executing, provided that symbol table is not empty. If it is
empty (contains no local macro variables), usually CALL SYMPUT creates the
variable in the closest nonempty symbol table.
2. However, there are three cases where CALL SYMPUT creates the variable in the
local symbol table, even if that symbol table is empty:
• Beginning with SAS Version 8, if CALL SYMPUT is used after a PROC SQL,
the variable will be created in a local symbol table.
• If the macro variable SYSPBUFF is created at macro invocation time, the
variable will be created in the local symbol table.
• If the executing macro contains a computed %GOTO statement, the variable will
be created in the local symbol table. A computed %GOTO statement is one that
uses a label that contains an & or a % in it. That is, a computed %GOTO
statement contains a macro variable reference or a macro call that produces a text
expression. Here is an example of a computed %GOTO statement:
%goto &home;
The symbol table that is currently available to a DATA step is the one that exists when
SAS determines that the step is complete. (SAS considers a DATA step to be complete
when it encounters a RUN statement, a semicolon after data lines, or the beginning of
another step.)
If an executing macro contains a computed %GOTO statement, or if the macro variable
SYSPBUFF is created at macro invocation time, but the local symbol table is empty,
CALL SYMPUT behaves as if the local symbol table was not empty, and creates a local
macro variable.
You might find it helpful to use the %PUT statement with the _USER_ option to
determine what symbol table the CALL SYMPUT routine has created the variable in.
Example Using CALL SYMPUT with Complete DATA Step and a
Nonempty Local Symbol Table
Consider the following example, which contains a complete DATA step with a CALL
SYMPUT statement inside a macro:
%macro env1(param1);
data _null_;
x = 'a token';
call symput('myvar1',x);
run;
%mend env1;
%env1(10)
data temp;
y = "&myvar1";
run;
64 Chapter 5 • Scopes of Macro Variables