Is there any ways to delete multiple data files based on their index number? For example, a process is generating 20 datasets named as Data1, Data2 ... Data20. I need to keep only data20. Is there any easy way to do that without mentioning all the file names? This process shouldn't interfere with data files named with different prefix (e,g., SASdata1, SASdata2 etc).
Use PROC DATASETS. It supports dataset lists.
Try this numeric suffix range:
data data1 data2 data3 data4;
run;
proc datasets nolist lib=work;
delete data1-data4;
run;
quit;
Any suffix:
data data1 data2 data3 data4 data10;
run;
proc datasets nolist lib=work;
delete data:;
run;
quit;
Use PROC DATASETS. It supports dataset lists.
Try this numeric suffix range:
data data1 data2 data3 data4;
run;
proc datasets nolist lib=work;
delete data1-data4;
run;
quit;
Any suffix:
data data1 data2 data3 data4 data10;
run;
proc datasets nolist lib=work;
delete data:;
run;
quit;
Thanks Tom. That works.
An alternative approach could be to write ALL of your sequenced datasets to your WORK SAS library, then only copy DATA20 to a permanent SAS library. When your SAS session ends only DATA20 is kept. As a general rule writing only datasets you want to keep to permanent SAS libraries means you don't need to tidy up at the end of your SAS sessions.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.