BookmarkSubscribeRSS Feed
Ronein
Onyx | Level 15

Hello

Let's say that I have many data sets in work library.

I want to keep only 2 data sets and delete all others.

How can I tell SAS to delete all data sets in work temporary library except of tables  tbl1 ,tbl2.

Thanks

Jow

 

4 REPLIES 4
Kurt_Bremser
Super User
proc sql noprint;
select memname into :datasets separated by " "
from dictionary.tables
where libname = "WORK" and memname not in ("DATASET1","DATASET2");
quit;

proc delete data=&datasets;
run;
ed_sas_member
Meteorite | Level 14

Hi @Ronein 

 

Here is an approach to do this.

It first put the list of the datasets to delete in a macrovariable and then uses PROC DATASETS to delete them.

proc sql;
	select memname
	into: list_delete separated by " "
	from dictionary.tables
	where libname="WORK" and lowcase(memname) not in("tbl1","tbl2");
run;

proc datasets;
	delete &list_delete.;
run;
Jagadishkatam
Amethyst | Level 16

please try the below code

 

proc sql;
select memname into: dat separated by ' ' from dictionary.tables where libname='WORK' and lowcase(memname) not in ('tbl1' 'tbl2');
quit;


proc datasets lib=work;
delete &dat;
run;
Thanks,
Jag
RichardDeVen
Barite | Level 11

Use the Proc DATASETS SAVE statement.

 

Example:

data a b c d e f g h i j k l;
  set sashelp.class;
run;

proc datasets nolist lib=work mt=data;
  save b c;
run;
quit;

Log

4096  proc datasets nolist lib=work mt=data;
4097    save b c;
4098  run;

NOTE: Saving WORK.B (memtype=DATA).
NOTE: Saving WORK.C (memtype=DATA).
NOTE: Deleting WORK.A (memtype=DATA).
NOTE: Deleting WORK.D (memtype=DATA).
NOTE: Deleting WORK.E (memtype=DATA).
NOTE: Deleting WORK.F (memtype=DATA).
NOTE: Deleting WORK.G (memtype=DATA).
NOTE: Deleting WORK.H (memtype=DATA).
NOTE: Deleting WORK.I (memtype=DATA).
NOTE: Deleting WORK.J (memtype=DATA).
NOTE: Deleting WORK.K (memtype=DATA).
NOTE: Deleting WORK.L (memtype=DATA).
4099  quit;

NOTE: PROCEDURE DATASETS used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds

 

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
  • 2087 views
  • 3 likes
  • 5 in conversation