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;
When you submit these
statements, you receive an error message:
WARNING: Apparent symbolic reference MYVAR1 not resolved.
This message appears
because the DATA step is complete within the environment of ENV1 (that
is, the RUN statement is within the macro) and because the local symbol
table of ENV1 is not empty (it contains parameter PARAM1). Therefore,
the CALL SYMPUT routine creates MYVAR1 as a local variable for ENV1,
and the value is not available to the subsequent DATA step, which
expects a global macro variable.
To see the scopes, add
a %PUT statement with the _USER_ option to the macro, and a similar
statement in open code. Now invoke the macro as before:
%macro env1(param1);
data _null_;
x = 'a token';
call symput('myvar1',x);
run;
%put ** Inside the macro: **;
%put _user_;
%mend env1;
%env1(10)
%put ** In open code: **;
%put _user_;
data temp;
y = "&myvar1"; /* ERROR - MYVAR1 is not available in open code. */
run;
When the %PUT _USER_
statements execute, they write the following information to the SAS
log:
** Inside the macro: **
ENV1 MYVAR1 a token
ENV1 PARAM1 10
** In open code: **
The MYVAR1 macro variable
is created by CALL SYMPUT in the local ENV1 symbol table. The %PUT
_USER_ statement in open code writes nothing to the SAS log, because
no global macro variables are created.
The following figure
shows all of the symbol tables in this example.