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
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.