How to Use PROC DELETE in SAS (With Example)


You can use the PROC DELETE statement in SAS to delete specific files in folders.

There are two common ways to use this statement in practice:

Method 1: Use PROC DELETE to Delete One Specific Dataset

/*define path to folder*/
libname folder1 '/home/u13181/folder1/';

/*delete dataset called data1 in folder called folder1*/
proc delete data=folder1.data1;
run;

Method 2: Use PROC DELETE to Delete Multiple Datasets

/*define path to folder*/
libname folder1 '/home/u13181/folder1/';

/*delete datasets called data2 and data3 in folder called folder1*/
proc delete data=folder1.data2 folder1.data3;
run;

The following examples show how to use PROC DELETE in practice with the following folder in SAS called folder1 that contains three datasets:

Example 1: Use PROC DELETE to Delete One Specific Dataset

We can use the following syntax with PROC DELETE to delete the dataset called data1 from the folder called folder1:

/*define path to folder*/
libname folder1 '/home/u13181/folder1/';

/*delete dataset called data1 in folder called folder1*/
proc delete data=folder1.data1;
run;

When we navigate back to folder1 we can see that the dataset called data1 has been deleted from the folder:

Example 2: Use PROC DELETE to Delete Multiple Datasets

We can use the following syntax with PROC DELETE to delete the datasets called data2 and data3 from the folder called folder1:

/*define path to folder*/
libname folder1 '/home/u13181/folder1/';

/*delete datasets called data2 and data3 in folder called folder1*/
proc delete data=folder1.data2 folder1.data3;
run;

When we navigate back to folder1 we can see that both datasets have been deleted from the folder:

Note: You can find the complete documentation for the PROC DELETE statement in SAS here.

Additional Resources

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

How to Use PROC COPY in SAS
How to Check if Dataset Exists in SAS
How to Concatenate Datasets in SAS

Leave a Reply

Your email address will not be published. Required fields are marked *