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: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1653 views
  • 0 likes
  • 3 in conversation