How can I delete datasets in SAS? 2

How can I delete datasets in SAS?

Deleting datasets in SAS is a simple process that can be done using the DATA step or through the SAS Explorer window. First, navigate to the location of the dataset you wish to delete. In the SAS Explorer window, right-click on the dataset and select “Delete.” Alternatively, in the DATA step, use the DROP statement to remove the dataset. It is important to note that once a dataset is deleted, it cannot be recovered. Therefore, it is recommended to make a backup copy of the dataset before deleting it. Deleting datasets in SAS is a quick and efficient way to manage and organize your data.

Delete Datasets in SAS (3 Examples)


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

Method 1: Delete One Dataset

proc datasetslibrary=work nolist;
    delete data2;
quit;

Method 2: Delete Multiple Datasets

proc datasetslibrary=work nolist;
    delete data2 data3;
quit;

Method 3: Delete All Datasets in Library

proc datasetslibrary=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 datasetslibrary=work nolist;
    delete data2;
quit;

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

proc datasetslibrary=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 datasetslibrary=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 datasetslibrary=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=workkill;

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

/*view all remaining datasets in work library*/
proc datasetslibrary=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:

Cite this article

stats writer (2024). How can I delete datasets in SAS?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-i-delete-datasets-in-sas/

stats writer. "How can I delete datasets in SAS?." PSYCHOLOGICAL SCALES, 1 Jul. 2024, https://scales.arabpsychology.com/stats/how-can-i-delete-datasets-in-sas/.

stats writer. "How can I delete datasets in SAS?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-i-delete-datasets-in-sas/.

stats writer (2024) 'How can I delete datasets in SAS?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-i-delete-datasets-in-sas/.

[1] stats writer, "How can I delete datasets in SAS?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, July, 2024.

stats writer. How can I delete datasets in SAS?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.

Download Post (.PDF)
Slide Up
x
PDF
Scroll to Top