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)
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.
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.
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.
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;
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!
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.
Ready to level-up your skills? Choose your own adventure.