BookmarkSubscribeRSS Feed
Tim_sas_
Obsidian | Level 7

Hello,

 

I have a problem to delete some datasets in one step. I have various datasets in my work library with the same name and different numbers (e.g. data_1, data_2, data_3, ...). I would like to delete all datasets which start with the term "data".

 

I have already tried to use PROC Delete, but something is missing. 

 

I would be very grateful if someone has an idea.

 

Many thanks,

 

Tim

 

Proc Delete Data= Data: ;
Run;
5 REPLIES 5
yabwon
Onyx | Level 15

According to the doc. for proc delete:

 

DATA= SAS-file(s)

specifies one or more SAS files that you want to delete.

Note: You can also use a numbered range list. For more information, see Data Set Lists in SAS Language Reference: Concepts. You cannot use a colon list.
 
Bart
_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



Reeza
Super User

Just a caveat with data set lists using a colon. You cannot use them in a DATA= location but you can in other places.

FYI unfortunately the link you're including doesn't seem to work?

 


@yabwon wrote:

According to the doc. for proc delete:

 

DATA= SAS-file(s)

specifies one or more SAS files that you want to delete.

Note: You can also use a numbered range list. For more information, see Data Set Lists in SAS Language Reference: Concepts. You cannot use a colon list.
 
Bart

 

PeterClemmensen
Tourmaline | Level 20

Do this

 

data data_1; a=1; run;
data data_2; a=1; run;
data data_3; a=1; run;

proc datasets library=work nolist;
   delete data_:;
quit;
yabwon
Onyx | Level 15

Maybe try like this:

data data_1 data_2 data_3 data_1000;
  set SASHELP.CLASS;  
run;

proc sql noprint;
  select catx(".", libname, memname)
  into :dataset_list separated by " "
  from dictionary.tables
  where memname like 'DATA%'
  ;
quit;

%put *&dataset_list.*;

proc delete data = &dataset_list.;
run;

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



Tom
Super User Tom
Super User

PROC DELETE only allows numeric lists, not the colon wildcard suffix. 

If there are gaps in the numbers or don't know the exact range you could try just using a larger number than you expect to have.

proc delete data=data_1-data_100; run;

But you will get warning message for the datasets that do not exist.

You could instead use PROC DATASETS as it does allow the colon wildcard.

 

Example:

1050  data data1 data2 data3 data100 ;
1051  run;

NOTE: The data set WORK.DATA1 has 1 observations and 0 variables.
NOTE: The data set WORK.DATA2 has 1 observations and 0 variables.
NOTE: The data set WORK.DATA3 has 1 observations and 0 variables.
NOTE: The data set WORK.DATA100 has 1 observations and 0 variables.
NOTE: DATA statement used (Total process time):
      real time           0.02 seconds
      cpu time            0.01 seconds


1052  proc datasets nolist nowarn lib=work;
1053      delete data: ;
1054  run;

NOTE: Deleting WORK.DATA1 (memtype=DATA).
NOTE: Deleting WORK.DATA100 (memtype=DATA).
NOTE: Deleting WORK.DATA2 (memtype=DATA).
NOTE: Deleting WORK.DATA3 (memtype=DATA).
1055  quit;

SAS Innovate 2025: Call for Content

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 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 929 views
  • 5 likes
  • 5 in conversation