BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
BayzidurRahman
Obsidian | Level 7

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

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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;

View solution in original post

3 REPLIES 3
Tom
Super User Tom
Super User

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;
BayzidurRahman
Obsidian | Level 7

Thanks Tom. That works.

SASKiwi
PROC Star

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.

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

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
  • 3 replies
  • 1352 views
  • 2 likes
  • 3 in conversation