How to Delete Datasets in SAS (3 Examples)


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.

Additional Resources

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

How to Use Proc Summary in SAS
How to Rename Variables in SAS
How to Create New Variables in SAS

Leave a Reply

Your email address will not be published.