To delete a dataset in SAS, the easiest way is to use PROC datasets and the DELETE statement:
proc datasets library=work;
delete dataset1;
run;
When working with data in SAS, sometimes we want to delete datasets to clear up space in our working directory or on our data servers.
We can easily delete datasets in SAS with PROC Datasets.
The key to getting rid of a SAS file is using the DELETE statement.
Deleting a Dataset using PROC Datasets in SAS
To delete a SAS file using PROC Datasets, all we need to do is list the file after a DELETE statement.
Let’s say I have a SAS file called “dataset1” in a directory which I’ve assigned to “mylib”. I can delete “dataset1” with the following SAS code:
proc datasets library=mylib;
delete dataset1;
run;
Deleting Multiple Datasets using PROC Datasets in SAS
To delete multiple SAS files using PROC Datasets, all we need to do is list the files after a DELETE statement.
Let’s say I have 2 SAS files called “dataset1” and “dataset2” in a directory which I’ve assigned to “mylib”. I can delete both SAS datasets with the following SAS code:
proc datasets library=mylib;
delete dataset1 dataset2;
run;
Deleting All Datasets in a Directory using PROC Datasets in SAS
To delete all datasets in a directory, after the DELETE statement we don’t list any files.
proc datasets library=mylib;
delete;
run;
Hopefully this article has been useful for you to understand how to use PROC datasets to delete datasets in your SAS code.
Leave a Reply