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
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;
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;
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;
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
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.