Hello
I want to check which data sets with start 'ttt' are in WORK library and put them in a macro variable with separation by '+'.
In this case the required macro variable will get value ttt1+ttt2+ttt3.
What is the way to do it please?
Data ttt1;
input ID;
cards
;
2
;
run;
Data ttt2;
input ID;
cards
;
3
;
run;
Data ttt3;
input ID;
cards
;
4
;
run;
Data www;
input City $;
cards
;
Athens
;
run;
On a new SAS session, you will see this:
102 Proc sql noprint; 103 select memname into : VVV separated by '+' 104 from dictionary.tables 105 where compress(libname)='WORK' AND compress(memname) like 'ttt%' 106 ; NOTE: No rows were selected. 107 run; NOTE: PROC SQL statements are executed immediately; The RUN statement has no effect. 108 %put &VVV; WARNING: Apparent symbolic reference VVV not resolved.
so I take it that your macro variable was already defined from a previous attempt.
Libnames and memnames are always uppercase in the DICTIONARY tables/views.
Use PROC SQL, and SELECT INTO with SEPARATED BY from DICTIONARY.TABLES.
Thanks,
In the result I get also data sets that are not "ttt" , why??
Data ttt1;
input ID;
cards
;
2
;
run;
Data ttt2;
input ID;
cards
;
3
;
run;
Data ttt3;
input ID;
cards
;
4
;
run;
Data www;
input City $;
cards
;
Athens
;
run;
Proc sql noprint;
select memname into : VVV separated by '+'
from dictionary.tables
where compress(libname)='WORK' AND compress(memname) like 'ttt%'
;
run;
%put &VVV;
Strange,
this query work well
Proc sql noprint;
select memname into : VVV separated by '+'
from dictionary.tables
where UPCASE(libname)='WORK'
AND UPCASE(memname) like 'TTT%'
;
run;
%put &VVV;
On a new SAS session, you will see this:
102 Proc sql noprint; 103 select memname into : VVV separated by '+' 104 from dictionary.tables 105 where compress(libname)='WORK' AND compress(memname) like 'ttt%' 106 ; NOTE: No rows were selected. 107 run; NOTE: PROC SQL statements are executed immediately; The RUN statement has no effect. 108 %put &VVV; WARNING: Apparent symbolic reference VVV not resolved.
so I take it that your macro variable was already defined from a previous attempt.
Libnames and memnames are always uppercase in the DICTIONARY tables/views.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.