BookmarkSubscribeRSS Feed
Ruhi
Obsidian | Level 7

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 . .
 

 

 

4 REPLIES 4
Ruhi
Obsidian | Level 7

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.

VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

because &CR macro is called outside of data step and is global. 

Kurt_Bremser
Super User

@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.

Astounding
PROC Star
Examine the SAS statement generated in each case.

When your program generates:

CR = "CR1" ;

it assigns three-character string to the data step variable CR.

When the program generates:

CR = CR1 ;

the program copies from the nonexistent variable CR1 to CR.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 748 views
  • 2 likes
  • 4 in conversation