How can I remove rows with missing values in SAS?

In SAS, you can use the missing value statement to remove rows with missing values. This statement can be used in a data step to identify and either delete or replace the missing values with a valid value. The missing values statement is a conditional statement that can be used to identify missing values in a dataset. You can also use the delete statement to delete any rows with missing values.


You can use the following basic syntax to remove rows with missing values from a dataset in SAS:

data new_data;
    set my_data;
    if cmiss(of _all_) then delete;
run;

This particular example creates a new dataset called new_data where any rows with missing values from the original dataset called my_data have been deleted.

The following example shows how to use this syntax in practice.

Example: Remove Rows with Missing Values in SAS

Suppose we have the following dataset in SAS that contains information about various basketball teams:

/*create dataset*/
data my_data;
    input team $ points assists;
    datalines;
Mavs 113 22
Pacers 95 .
Cavs . .
Lakers 114 20
Heat 123 39
Kings . 22
Raptors 105 11
Hawks 95 25
Magic 103 26
Spurs 119 .
;
run;

/*view dataset*/
proc print data=my_data;

Notice that there are several rows with missing values.

We can use the following code to create a new dataset in which we remove all rows from the existing dataset that have missing values in any column:

/*create new dataset that removes rows with missing values from existing dataset*/
data new_data;
    set my_data;
    if cmiss(of _all_) then delete;
run;

/*view new dataset*/
proc print data=new_data;

We can see that all rows with missing values have been removed from the dataset.

Note #1: The argument _all_ within the CMISS function specifies that SAS should look for missing values in all columns for each row.

Note #2: You can find the complete documentation for the CMISS function .

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

x