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.

 

 

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