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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: