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;
According to the doc. for proc delete:
specifies one or more SAS files that you want to delete.
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
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;
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
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;
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!
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.