Hello,W
I have program list below, I found out when I add underscore '_' behind the macro i, the log showed that error message. But it works fine after I removed it. What if I would like to add _ behind i?
%let Y1=Cin; %let Y2=Kan; %let Y3=Vand; %macro import; %do i = 1 %to 3; %let folder="Pathway"; PROC IMPORT OUT=work.Repeater_&&Y&i. datafile=&folder dbms=xlsx replace; sheet=ARI; run; data Repeater_&&Y&i._; set Repeater_&&Y&i.; %do k = 1 %to 5; CaseID_&k. =upcase(compress(CaseID_&k., '-')); put CaseID_&k.; %end; run; %end; %mend; %import;
It seems like the warning message shown from the codes:
data Repeater_&&Y&i._;
WARNING: Apparent symbolic reference Y3_ not resolved.
You need a double dot to separate repeater_&&Y&i from the following underscore.
For future reference, when you have these types of issues with macro variables, you can use
options mprint symbolgen;
to get more information in the SAS log that will help you debug macro issues. Had you done that, the log would immediately identify the problem
SYMBOLGEN: && resolves to &. SYMBOLGEN: Macro variable I resolves to 1 WARNING: Apparent symbolic reference Y1_ not resolved. Repeater_&Y1_
Of course, you could make your life even easier by not putting an underscore following a macro variable. Instead of
data Repeater_&&Y&i._;
with an underscore (or really any character) after the macro variable at the end, you could use
data _Repeater_&&Y&i;
and then these types of problem go away.
You need a double dot to separate repeater_&&Y&i from the following underscore.
For future reference, when you have these types of issues with macro variables, you can use
options mprint symbolgen;
to get more information in the SAS log that will help you debug macro issues. Had you done that, the log would immediately identify the problem
SYMBOLGEN: && resolves to &. SYMBOLGEN: Macro variable I resolves to 1 WARNING: Apparent symbolic reference Y1_ not resolved. Repeater_&Y1_
Of course, you could make your life even easier by not putting an underscore following a macro variable. Instead of
data Repeater_&&Y&i._;
with an underscore (or really any character) after the macro variable at the end, you could use
data _Repeater_&&Y&i;
and then these types of problem go away.
This brings up another macro writing issue.
%do i = 1 %to 3;
%let folder="Pathway";
PROC IMPORT OUT=work.Repeater_&&Y&i.
datafile=&folder
dbms=xlsx replace;
sheet=ARI;
run;
The above PROC IMPORT is repeated three times, because &i goes from 1 to 3, but it is producing the exact same data set each time, only the data set name changes. I don't really see a point to doing this three times, and getting three identical data sets.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.