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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Your problem is when you try to attach the underscore. Use an extra dot after the i

View solution in original post

4 REPLIES 4
Tom
Super User Tom
Super User

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_
PeterClemmensen
Tourmaline | Level 20

Your problem is when you try to attach the underscore. Use an extra dot after the i

Tom
Super User Tom
Super User

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;

 

ybz12003
Rhodochrosite | Level 12

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.

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!

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
  • 1775 views
  • 0 likes
  • 3 in conversation