How to use the CMISS Function in SAS?

The CMISS function in SAS is used to calculate the cumulative missing values in a data set. It takes two arguments: the data set and the variable for which to calculate the cumulative missing values. It returns a single value which is the total number of missing values for the specified variable in the data set. The CMISS function is useful for identifying trends in missing data in a given data set.


You can use the CMISS function in SAS to count the number of missing values in each row of a dataset.

Here is one common way to use this function in practice:

data new_data;
    set my_data;
    total_missing = cmiss(of team -- assists);
run;

This particular example creates a new dataset called new_data that includes a column called total_missing that counts the number of missing values in each row between the columns named team and assists.

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

Example: Use CMISS in SAS to Count Number of Missing Values in Each Row

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

/*create dataset*/
data my_data;
    input team $ points assists;
    datalines;
Cavs 12 5
Cavs 14 7
Warriors 15 9
. 18 9
Mavs 31 7
Mavs . 5
. . 3
Celtics 36 9
Celtics 40 7
;
run;

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

Notice that several rows have missing values.

We can use the CMISS function to count the number of missing values in each row:

The following examples show how to use each method in practice with the following dataset in SAS:

/*create new dataset that counts number of missing values in each row*/
data new_data;
    set my_data;
    total_missing = cmiss(of team -- assists);
run;

CMISS function in SAS

The new column called total_missing displays the number of missing values in each row.

For example:

  • The first row contains 0 missing values.
  • The second row contains 0 missing values.
  • The third row contains 0 missing values.
  • The fourth row contains 1 missing value.

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

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

x