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,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.

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
ybz12003
Rhodochrosite | Level 12
Thank you for the great suggestion, both ways worked!
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 3 replies
  • 16623 views
  • 3 likes
  • 2 in conversation