Hi,
I created a macro variable using call symput but I am unable to use its value in next step. I have looked at similar examples but I can't figure out the issue. Any help is very much appreciated. So all other macro varaibles except &CR were provided my macro statement and resolve well and are decoded by fitstats1 data really well but CR is coming as CR1 not resolved. Log:
295 %put &cr;
SYMBOLGEN: Macro variable CR resolves to CR1
CR1
296 options symbolgen;
297 data fitstats1;
298 set fitstats1;
299 id=&id;
SYMBOLGEN: Macro variable ID resolves to "BZ01"
300 Landmark=&ldmk;
SYMBOLGEN: Macro variable LDMK resolves to "L2"
301 side=&side;
SYMBOLGEN: Macro variable SIDE resolves to "R"
302 PushNum=&cycle;
SYMBOLGEN: Macro variable CYCLE resolves to 1
303 Model=1;
304 year=&year;
SYMBOLGEN: Macro variable YEAR resolves to 2013
305 CR= &CR;
SYMBOLGEN: Macro variable CR resolves to CR1
306 run;
NOTE: Variable CR1 is uninitialized.
data _null_;
set &d2;
if _n_ =1 then call symput("CR",RM);
run;
%put &CR;
ods exclude all;
proc glm data= force1;
model force= disp /ss3 noint;
ods output FitStatistics=fitstats1 ParameterEstimates=Pestimate1;
run;
options symbolgen;
data fitstats1;
set fitstats1;
id=&id;
Landmark=&ldmk;
side=&side;
PushNum=&cycle;
Model=1;
year=&year;
CR= &CR;
run;
Print of fitstats1
Obs | Dependent | RSquare | CV | RootMSE | DepMean | id | Landmark | side | PushNum | Model | year | CR | CR1 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | force | 0.988213 | 13.71906 | 1.318715 | 9.612285 | BZ01 | L2 | R | 1 | 1 | 2013 | . | . |
I resolved my problem by adding quotes around like this, CR= "&CR"; But I would like to understand why this happened. If anyone can help.
Thanks.
because &CR macro is called outside of data step and is global.
@Ruhi wrote:
I resolved my problem by adding quotes around like this, CR= "&CR"; But I would like to understand why this happened. If anyone can help.
Thanks.
Look at the symbolgen messages for ID, LDMK and SIDE. They all contain the quotes tha are needed where they are used. CR does not contain quotes.
Since having quotes in macro variables often causes problems, I would define all those variables without quotes and wrap them in double quotes where needed.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.