One of the strange things about both CALL SYMPUTX() and CALL SYMPUT() is which symbol table it will use to create a new symbol (what most people normally call macro variables).
The strange thing is that SAS does not always create a symbol table for every running macro. Macros that do not have any local macro variables do not get a symbol table defined. In which case the new macro variable will be created in the next higher symbol table. Which could be the local symbol table of the calling macro.
By adding a parameter to the macro definition they insured that the macro will have at least one local symbol so that there will be a local symbol table created when it runs.
Try this example.
%macro nosymtable;
* This macro will have no symbol table;
data _null_;
call symputx('nosymboltable','xxx');
run;
%mend nosymtable;
%macro makemvar(mvar,value);
data _null_;
call symputx("&mvar","&value");
run;
%nosymtable;
%put _user_;
%mend makemvar;
%makemvar(test2,yyy);
What symbol table has the value xxx in the macro variable nosymboltable?
MAKEMVAR MVAR test2
MAKEMVAR NOSYMBOLTABLE xxx
MAKEMVAR TEST2 yyy
MAKEMVAR VALUE yyy
GLOBAL SQLEXITCODE 0
GLOBAL SQLOBS 1
GLOBAL SQLOOPS 136
GLOBAL SQLRC 0
GLOBAL SQLXOBS 0
GLOBAL SQLXOPENERRS 0
GLOBAL SYS_SQL_IP_ALL -1
GLOBAL SYS_SQL_IP_STMT
One of the strange things about both CALL SYMPUTX() and CALL SYMPUT() is which symbol table it will use to create a new symbol (what most people normally call macro variables).
The strange thing is that SAS does not always create a symbol table for every running macro. Macros that do not have any local macro variables do not get a symbol table defined. In which case the new macro variable will be created in the next higher symbol table. Which could be the local symbol table of the calling macro.
By adding a parameter to the macro definition they insured that the macro will have at least one local symbol so that there will be a local symbol table created when it runs.
Try this example.
%macro nosymtable;
* This macro will have no symbol table;
data _null_;
call symputx('nosymboltable','xxx');
run;
%mend nosymtable;
%macro makemvar(mvar,value);
data _null_;
call symputx("&mvar","&value");
run;
%nosymtable;
%put _user_;
%mend makemvar;
%makemvar(test2,yyy);
What symbol table has the value xxx in the macro variable nosymboltable?
MAKEMVAR MVAR test2
MAKEMVAR NOSYMBOLTABLE xxx
MAKEMVAR TEST2 yyy
MAKEMVAR VALUE yyy
GLOBAL SQLEXITCODE 0
GLOBAL SQLOBS 1
GLOBAL SQLOOPS 136
GLOBAL SQLRC 0
GLOBAL SQLXOBS 0
GLOBAL SQLXOPENERRS 0
GLOBAL SYS_SQL_IP_ALL -1
GLOBAL SYS_SQL_IP_STMT
Register Today!
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.