BookmarkSubscribeRSS Feed
VaheMartirosyan
Fluorite | Level 6

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. 

4 REPLIES 4
ChrisNZ
Tourmaline | Level 20

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..  ]

VaheMartirosyan
Fluorite | Level 6
Let me try. Thanks
Kurt_Bremser
Super User
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.

ChrisNZ
Tourmaline | Level 20

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).

 

 

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 4 replies
  • 2866 views
  • 3 likes
  • 3 in conversation