What is the MISSING Function in SAS (With Examples)

The MISSING function in SAS is a powerful tool that allows users to detect and replace missing values in a dataset. For example, the MISSING function can be used to detect missing values in a numeric variable, such as a customer’s age, and then replace those missing values with a mean or median age. Similarly, it can be used to detect missing character values, such as a customer’s address, and replace those values with a default value, such as ‘unknown’. In this way, the MISSING function can help to ensure that a dataset is complete and ready for analysis.


You can use the MISSING function in SAS to check if a variable contains a missing value.

This function uses the following syntax:

MISSING(expression)

where:

  • expression: The name of a character or numeric variable

This function will return 0 if the variable does not contain a missing value or 1 if it does contain a missing value.

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

Example: How to Use the MISSING Function in SAS

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

/*create dataset*/
data my_data;
    input team $ position $ points assists;
    datalines;
A Guard 14 4
A Guard 22 6
A Guard 24 9
A Forward 13 8
A Forward 13 9
A . 10 5
B Guard 24 4
B Guard . 6
B Forward 34 2
B Forward 15 5
B Forward 23 5
B . 10 4
;
run;

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

We can create a new dataset and use the MISSING function to create a variable that checks if each row in the position column is missing a value or not:

/*create new dataset*/
data new_data;
    set my_data;
    missing_position = missing(position);
run;

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

SAS MISSING function example

The new column called missing_position contains a value of 0 if there is no missing value in the position column and a value of 1 if there is a missing value.

Note: Although row 8 has a missing value in the points column, the missing_position column contains a value of 0 because there is no missing value in the position column.

Also note that you can use an IF ELSE function with the MISSING function to return values other than 0 and 1.

/*create new dataset*/
data new_data;
    set my_data;
    if missing(position) then missing_position = 'yes';
    else missing_position = 'no';
run;

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

The new column called missing_position contains a value of no if there is no missing value in the position column and a value of yes if there is a missing value.

Note: You can find the complete documentation for the SAS MISSING function .

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

x