BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
raivester
Quartz | Level 8

Hello, below is a sample of the code I'm trying to run; however, I keep getting errors messages: "Apparent symbolic reference I_TEMP not resolved" and about the & symbol not being recognized and thus being ignored. Any ideas what is going on here?

 

%macro create(years);
	%do i=2017 %to &years;

		/*Comment.*/
		data merge_&i_temp;
		 	set annual.data_ab_&i;
		  	keep year state state_code;
		  	year = &i;
		  	if stcode = "01" then state = "AL" ;
			if stcode = "02" then state = "AK" ;
	
		  	length state_code $43;

		  	array array var1 var2 var3;

		  	do a=1 to 3;
			  	state_code = array[a];
				output;
		  	end;

		 run;
	 
		 /*Comment.*/
		 data merge_&i_temp;
		 	set merge_&i_temp;
			if state_code NE " ";
		 run;

		/*More data and proc steps.*/

	%end;

%mend create;

%create(2019)
1 ACCEPTED SOLUTION

Accepted Solutions
ketpt42
Quartz | Level 8

The macro processor is looking for the macro variable %i_temp, which likely does not exist. You need to separate the macro variable &i from the rest of the text by using a period.
Instead of this:

merge_&i_temp;

You should have this:

merge_&i._temp;

You'll need to replace all instances of &i with &i.

View solution in original post

5 REPLIES 5
ketpt42
Quartz | Level 8

The macro processor is looking for the macro variable %i_temp, which likely does not exist. You need to separate the macro variable &i from the rest of the text by using a period.
Instead of this:

merge_&i_temp;

You should have this:

merge_&i._temp;

You'll need to replace all instances of &i with &i.

raivester
Quartz | Level 8
Thank you! This was exactly what I needed. Originally I named the data set merge_&i and not merge_&i_temp. Apparently not having the period did not matter in the first case since &i ended the data set name.
PaigeMiller
Diamond | Level 26

The idea presented in your earlier thread, @raivester , is to not use data sets by year, and then you don't need macros, and then you don't run into macro errors.

 

You could combine all of the annual data sets into one large data set covering multiple years, and all of these coding difficulties caused by macros are gone.

--
Paige Miller
Reeza
Super User
Your second data step is unnecessary.
Tom
Super User Tom
Super User

You need to use period to let macro processor know where you macro variable name ends.

But if you had put the numeric suffix at the END of the name instead of trying to embed it in the middle it wouldn't have mattered. 

merge_temp_&i

Plus then you can use a range of dataset names.

data want;
  set merge_temp_2017 - merge_temp_&years ;
run;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 5 replies
  • 1037 views
  • 3 likes
  • 5 in conversation