Figure 5.10 The Symbol Tables with the CALL SYMPUT Routine Generating an Incomplete DATA Step
Example Using CALL SYMPUT with a Complete DATA Step and an
Empty Local Symbol Table
In the following example, ENV3 does not use macro parameters. Therefore, its local
symbol table is empty:
%macro env3;
data _null_;
x = 'a token';
call symput('myvar3',x);
run;
%put ** Inside the macro: **;
%put _user_;
%mend env3;
70 Chapter 5 Scopes of Macro Variables
%env3
%put ** In open code: **;
%put _user_;
data temp;
y="&myvar3";
run;
In this case, the DATA step is complete and executes within the macro, but the local
symbol table is empty. So, CALL SYMPUT creates MYVAR3 in the closest available
nonempty symbol table—the global symbol table. Both %PUT statements show that
MYVAR3 exists in the global symbol table:
** Inside the macro: **
GLOBAL MYVAR3 a token
** In open code: **
GLOBAL MYVAR3 a token
Example Using CALL SYMPUT with SYSPBUFF and an Empty Local
Symbol Table
In the following example, the presence of the SYSPBUFF automatic macro variable
causes CALL SYMPUT to behave as if the local symbol table were not empty, even
though the macro ENV4 has no parameters or local macro variables:
%macro env4 /parmbuff;
data _null_;
x = 'a token';
call symput('myvar4',x);
run;
%put ** Inside the macro: **;
%put _user_;
%put &syspbuff;
%mend env4;
%env4
%put ** In open code: **;
%put _user_;
%put &syspbuff;
data temp;
y="&myvar4"; /* ERROR - MYVAR4 is not available in open code */
run;
The presence of the /PARMBUFF specification causes the SYSPBUFF automatic macro
variable to be created. So, when you call macro ENV4, CALL SYMPUT creates the
macro variable MYVAR4 in the local symbol table (that is, in ENV4's). This action
happens even though the macro ENV4 has no parameters and no local variables.
The results of the %PUT statements prove the following:
the score of MYVAR4 is listed as ENV4
the reference to SYSPBUFF does not resolve in the open code %PUT statement
because SYSPBUFF is local to ENV4
Special Cases of Scope with the CALL SYMPUT Routine 71
** Inside the macro: **
b ENV4 MYVAR4 a token
** In open code: **
WARNING: Apparent symbolic reference SYSPBUFF not resolved.
For more information, see “SYSPBUFF Automatic Macro Variable” on page 220.
72 Chapter 5 Scopes of Macro Variables
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset