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.
log plz. error notes?
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.
make this change
"&MYVAR.%"
to double quotes and test again
Macro references within single quotes do not get resolved: like '&MYVAR.%'
Switch to double quotes: like "&MYVAR.%"
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.
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!
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.
Ready to level-up your skills? Choose your own adventure.