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

The code I have below works find.  While, I would like to replace the MYDATA for the like conduction with a macro. 

 

 

proc sql ;		
	/* get all my dataset file names into a macro var */
	select 		
		trim(libname) || '.' || memname into :dataset_vars separated by ' '
	from dictionary.tables
	where upcase(libname)="WORK"
	and upcase(memname) like 'MYDATA%' 
	;
quit;
/* stack my datasets */
data ALL_MYDATA;
	set &dataset_vars;* (drop=month);
run;

 When I use this code I get an error no rows were selected.

 

%LET myvar = MYDATA;
proc sql ;		
	/* get all my dataset file names into a macro var */
	select 		
		trim(libname) || '.' || memname into :dataset_vars separated by ' '
	from dictionary.tables
	where upcase(libname)="WORK"
	and upcase(memname) like '&MYVAR.%' 
	;
quit;
/* stack my datasets */
data ALL_MYDATA;
	set &dataset_vars;* (drop=month);
run;

What changes do I need to make for this code to work correctly and fetch my data.

Thank you for any assistance or suggestions.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

make this change

 

 "&MYVAR.%" 

 

to double quotes and test again

View solution in original post

5 REPLIES 5
novinosrin
Tourmaline | Level 20

log plz. error notes?

VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

 the first code provides this log:

 

NOTE: There were 7 observations read from the data set WORK.MYDATA1707.
NOTE: There were 2 observations read from the data set WORK.MYDATA1708.
NOTE: There were 6 observations read from the data set WORK.MYDATA1709.
NOTE: There were 4 observations read from the data set WORK.MYDATA1710.
NOTE: There were 5 observations read from the data set WORK.MYDATA1711.
NOTE: There were 3 observations read from the data set WORK.MYDATA1801.
NOTE: There were 1 observations read from the data set WORK.MYDATA1802.
NOTE: There were 3 observations read from the data set WORK.MYDATA1803.
NOTE: There were 2 observations read from the data set WORK.MYDATA1804.
NOTE: There were 2 observations read from the data set WORK.MYDATA1806.
NOTE: The data set WORK.ALL_MYDATA has 35 observations and 52 variables

 

 

the second code provides this log when I try to use a macro. 

NOTE: No rows were selected.

novinosrin
Tourmaline | Level 20

make this change

 

 "&MYVAR.%" 

 

to double quotes and test again

Astounding
PROC Star

Macro references within single quotes do not get resolved:  like '&MYVAR.%'

 

Switch to double quotes:  like "&MYVAR.%"

VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

That worked.

 

Thank you @novinosrin and @Astounding for the reminder to use double quotes for resolving macros.  It must be getting late and I am just overlooked and forgetting.  Thank both of you.

 

 

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