21.7 C
London
Wednesday, July 23, 2025
HomeSASData Munging in SASHow to Delete Datasets in SAS (3 Examples)

How to Delete Datasets in SAS (3 Examples)

Related stories

Learn About Opening an Automobile Repair Shop in India

Starting a car repair shop is quite a good...

Unlocking the Power: Embracing the Benefits of Tax-Free Investing

  Unlocking the Power: Embracing the Benefits of Tax-Free Investing For...

Income Splitting in Canada for 2023

  Income Splitting in Canada for 2023 The federal government’s expanded...

Can I Deduct Home Office Expenses on my Tax Return 2023?

Can I Deduct Home Office Expenses on my Tax...

Canadian Tax – Personal Tax Deadline 2022

  Canadian Tax – Personal Tax Deadline 2022 Resources and Tools...

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

Subscribe

- Never miss a story with notifications

- Gain full access to our premium content

- Browse free from up to 5 devices at once

Latest stories