Hello
Let's say that I have many data sets in work library (let's say 2000 data sets).
I want to keep only one data set called tbl_aaa and delete all other data sets.
What is the way to tell SAS to delete all data sets in work library except of tbl_aaa?
Copy the dataset to a different library (or create it there in the first place), and use proc datasets with the kill option on WORK.
Or do this:
proc sql noprint;
select cats('WORK.',memname) into :to_delete separated by ' '
from dictionary.tables
where libname = 'WORK' and memname ne 'TBL_AAA':
quit;
proc delete data=&to_delete.;
run;
Alternatively you can use the proc datasets as below, but you need the macro variable to_delete from @Kurt_Bremser code and use it in proc datasets
proc datasets lib=work memtype=data;
delete &to_delete;
run;
quit;
Yet another (just for fun?) approach would be "building a shelter" 😉
data a b c d e f;
set sashelp.class;
run;
options dlcreatedir;
libname shelter "%sysfunc(pathname(WORK))/shelter";
data shelter.a;
set a;
run;
/*
proc datasets kill lib=work noprint;
run;
*/
proc delete lib = work data = _all_;
run;
data a;
set shelter.a;
run;
All the best
Bart
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!
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.