BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Ronein
Onyx | Level 15

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?

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
Use SAVE statement in PROC DATASETS .

proc datasets lib=work memtype=data nodetails ;
save tbl_aaa ;
quit;

View solution in original post

4 REPLIES 4
Kurt_Bremser
Super User

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;
Jagadishkatam
Amethyst | Level 16

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;

 

 

Thanks,
Jag
yabwon
Amethyst | Level 16

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 

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



Ksharp
Super User
Use SAVE statement in PROC DATASETS .

proc datasets lib=work memtype=data nodetails ;
save tbl_aaa ;
quit;

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
  • 17970 views
  • 9 likes
  • 5 in conversation