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.
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!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.