How set all datasets from one library?
Datasets have different names. I need to keep the Visit variable from all datasets.
Purpose: Understand that how many values the study has under the Visit variable.
You could query the dictionary, or the view SASHELP.VCOLUMN, and keep all the entries with LIBNAME= your libname and NAME='VISIT'.
You might have to use the upcase function, I think not but I might be mistaken.
Be sure to clear as many libnames as possible beforehand to speed up reading the view.
[Edit: LIBNAME=, not MEMNAME= , sorry about that, late day reply.. ]
proc sql noprint;
select catx(".",libname,memname) !! " (keep=visit)" into :dsnames separated by " "
from dictionary.columns
where libname = "LIBNAME" and upcase(name) = "VISIT";
quit;
data all;
set &dsnames.;
run;
Note that there is a length limit for macro variables (65535), which might be reached if you have very many datasets with that variable in your library.
Another way, without macros and without using the potentially slow dictionary.
ods output members=MEMBERS;
proc datasets lib=WORK mt=data;
run;
ods output close;
data _null_;
set MEMBERS end=LASTOBS;
if _N_=1 then call execute ('data _V/view=_V; set ');
call execute(NAME);
if LASTOBS then call execute(' indsname=_DS; DS=_DS; keep VISIT DS;run;');
run;
proc freq;
tables VISIT;
run;
You can use variable DS if you want analysis by source (table name).
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.