How to Use the CMISS Function in SAS (With Example)


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.

And so on.

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

Additional Resources

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

How to Count Missing Values in SAS
How to Remove Rows with Missing Values in SAS
How to Replace Missing Values with Zero in SAS

Featured Posts

Leave a Reply

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