How to delete datasets in SAS (3 Examples)

Deleting datasets in SAS is done with the PROC DELETE statement. You can delete a single dataset, a group of datasets, or all datasets in a library by specifying the dataset or library in the statement. For example, to delete a single dataset you can use the dataset name in the statement like this: PROC DELETE DATA=mydataset; To delete a group of datasets you can use the wildcard character in the statement like this: PROC DELETE DATA=mylibrary.*; To delete all datasets in a library you can use the libname in the statement like this: PROC DELETE DATA=mylibrary;


Here are the three most common ways to delete datasets in SAS:

Method 1: Delete One Dataset

proc datasets library=work nolist;
    delete data2;
quit;

Method 2: Delete Multiple Datasets

proc datasets library=work nolist;
    delete data2 data3;
quit;

Method 3: Delete All Datasets in Library

proc datasets library=work kill;

The following examples show how to use each method using a WORK library that contains three datasets: data1, data2, and data3.

Example 1: Delete One Dataset

We can use the following code to delete only the dataset titled data2 in our WORK library:

/*delete data2 from work library*/
proc datasets library=work nolist;
    delete data2;
quit;

We can then use the following code to list all remaining datasets in our WORK library:

proc datasets library=work memtype=data;
run;
quit;

We can see that only data1 and data3 remain in our WORK library. The dataset called data2 has been deleted.

Example 2: Delete Multiple Datasets

We can use the following code to delete the datasets titled data2 and data3 in our WORK library:

/*delete data2 from work library*/
proc datasets library=work nolist;
    delete data2 data3;
quit;

We can then use the following code to list all remaining datasets in our WORK library:

/*view all remaining datasets in work library*/
proc datasets library=work memtype=data;
run;
quit;

We can see that only data1 remains in our WORK library. The datasets data2 and data3 have been deleted.

Example 3: Delete All Datasets in Library

We can use the following code to delete all datasets in our WORK library:

/*delete all datasets from work library*/
proc datasets library=work kill;

We can then use the following code to list all remaining datasets in our WORK library:

/*view all remaining datasets in work library*/
proc datasets library=work memtype=data;
run;
quit;

We can see that there are no remaining datasets in our WORK library since we used the KILL function to delete all datasets.

The following tutorials explain how to perform other common tasks in SAS:

x