In Base SAS you can use the DATASETS procedure to determine the SAS data sets in a library, and you can use the DELETE statement to delete data sets. Did you know that you can do the same operations from within the SAS/IML language?
The following DATA step creates four SAS data sets, each with one observation:
data a b c d; x=1; run; |
In Base SAS, you can use the following statements to list the data sets in the WORK library:
proc datasets library=work; run; |
The DATASETS procedure is an interactive procedure (like PROC IML), so the procedure is still active after a RUN statement. You can submit the following statements to delete the WORK.A data set:
delete a; run; |
You can perform similar operations from within the SAS/IML language. For example, the following statements use the EXIST function in Base SAS to check whether WORK.B exists. If so, the DELETE subroutine deletes the data set.
proc iml; if exist("b") then call delete("work", "b"); |
You can also use the DATASETS function in SAS/IML to determine which data sets exist in a library:
ds = datasets("work"); print ds; |
A new feature in SAS/IML 9.22 is that you can call the DELETE subroutine to delete all data sets specified in a vector:
call delete(ds); |
If you are using a version of SAS/IML prior to 9.22, you have to call the DELETE subroutine in a loop to delete multiple data sets.
3 Comments
Pingback: Cleaning up after yourself: Deleting data sets - The DO Loop
Hi
I am new to sas I am looking for a drop statement using sas proc select.
Welcome to SAS! You can ask programming questions at the SAS Support Communities. There are many helpful people there. Post data and sample code when possible.