Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What is wrong with Call symput()?

Status
Not open for further replies.

6656

Programmer
Nov 5, 2002
104
US
Hi, Any one can tell why I could not get my macro variables resolved? Sometimes it worked. Pls see below log. Thanks, Mike

133 %macro aa (_var= xyz0103-xyz0108);
134 DATA varname ;
135 do j=1 to 2;
136 varname=scan( "&_var",j,'-');
137 CALL SYMPUT('tmpvar'||left(j),varname);
138 output;
139 end;
140 RUN;
141 %mend aa;
142 %aa;

NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).
142:99
NOTE: The data set WORK.VARNAME has 2 observations and 2 variables.
NOTE: DATA statement used:
real time 0.02 seconds
cpu time 0.02 seconds


WARNING: Apparent symbolic reference TMPVAR1 not resolved.
WARNING: Apparent symbolic reference TMPVAR2 not resolved.
143 %put tmevar= &tmpvar1 &tmpvar2;
tmevar= &tmpvar1 &tmpvar2
 
Try this:
DATA _null_;
%macro aa (_var= xyz0103-xyz0108);
do j=1 to 2;
varname=scan( "&_var",j,'-');
CALL SYMPUT('tmpvar'||left(j),varname);
output;
end;
%mend aa;
%aa;
run;
You may want to add a trim function to varname to remove trailling blanks.


SYMPUT puts the macro variable in the most local nonempty symbol table. The first time you run you macro, macro variables are created as local macro variables. %put statement is out of the scope of the macro variable. But when you run your macro the second time, local symbol table is not empty any more. Macro variables are created in the nearest nonempty symbol table, in your case, there is no next level of local macro variable table. Therefore, they are created in the globle macro variable table. That is why your code does not work the first time. It works after the first time.
 
Thanks Teralearner, you're right. A macro varible created by SYMPUT()must be used only after RUN statement.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top