How to Use PROC DELETE in SAS (With Example)

PROC DELETE is a procedure in SAS that is used to delete observations from a dataset. It can be used to delete specific observations or groups of observations that meet certain criteria. An example of PROC DELETE would be to delete all observations where the variable ‘age’ is greater than 50 years. This can be done by using the ‘where’ statement in PROC DELETE. For example, PROC DELETE data=mydata where age >50;


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 .

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

x