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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 500 views
  • 2 likes
  • 3 in conversation