Hello,
I have macro coding below.
%let X1=ulungothsp; %let X2=uairwayothsp; %let X3=uhdefectsp; %let X4=uheartothsp; %let X5=ugastroothsp; %let folder="Designed pathway.xlsx"; %macro export; %do i = 1 %to 5; data &&X&i.; set test (keep=&&X&i.); if &&X&i. ^= ' '; &&X&i.=upcase(&&X&i.); run; proc sort data=&&X&i. nodupkey out=&&X&i._; by &&X&i.; run; PROC EXPORT DATA=&&X&i._ outfile=&folder dbms=xlsx replace; sheet=&&X&i.; run; %end; %mend; %export;
The log window showed error messages below when running.
NOTE: Line generated by the macro variable "I".
1 &X1_
-
22
200
WARNING: Apparent symbolic reference X1_ not resolved.
ERROR 22-322: Expecting a name.
ERROR 200-322: The symbol is not recognized and will be ignored.
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.X1_ may be incomplete. When this step was stopped there were 0
observations and 0 variables.
NOTE: PROCEDURE SORT used (Total process time):
real time 0.02 seconds
cpu time 0.03 seconds
NOTE: Line generated by the macro variable "I".
1 &X1_
-
22
200
WARNING: Apparent symbolic reference X1_ not resolved.
NOTE: PROCEDURE EXPORT used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
NOTE: The SAS System stopped processing this step because of errors.
ERROR 22-322: Expecting a name.
ERROR 200-322: The symbol is not recognized and will be ignored.
.
.
.
Please let me know how to fix it, thank you.
Your problem is when you try to attach the underscore. Use an extra dot after the i
Make sure you have one period for every macro variable reference.
14 %let X1=ulungothsp; 15 %let i=1 ; 16 %put &&x&i; ulungothsp 17 %put &&x&i._; WARNING: Apparent symbolic reference X1_ not resolved. &x1_ 18 %put &&x&i.._; ulungothsp_
Your problem is when you try to attach the underscore. Use an extra dot after the i
https://www.amazon.com/Doctor-hurts-when-Jokes-Cartoons/dp/150043230X
Don't use so many &&&&&s.
Figure out the name once and save it.
%macro export;
%local i varname dsname ;
%do i = 1 %to 5;
%let varname=&&x&i ;
%let dsname=&varname._;
proc sql;
create table &dsname as
select distinct upcase(&varname) as &varname
from test
where &varname ne ' '
order by 1
;
quit;
proc export dbms=xlsx outfile=&folder replace data=&dsname;
sheet=&varname;
run;
%end;
%mend;
Even though I change &&X&i.._, the error messgages are still showning.
NOTE: Line generated by the macro variable "I".
1 &X1_
-
22
200
WARNING: Apparent symbolic reference X1_ not resolved.
ERROR 22-322: Expecting a name.
ERROR 200-322: The symbol is not recognized and will be ignored.
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.X1_ may be incomplete. When this step was stopped there were 0
observations and 0 variables.
WARNING: Data set WORK.X1_ was not replaced because this step was stopped.
NOTE: PROCEDURE SORT used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
NOTE: Line generated by the macro variable "I".
1 &X1_
-
22
200
WARNING: Apparent symbolic reference X1_ not resolved.
NOTE: PROCEDURE EXPORT used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
NOTE: The SAS System stopped processing this step because of errors.
ERROR 22-322: Expecting a name.
ERROR 200-322: The symbol is not recognized and will be ignored.
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.