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

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
Onyx | Level 15

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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 13200 views
  • 9 likes
  • 5 in conversation