How to use the NMISS Function in SAS (With Example)

The NMISS function in SAS is a useful function for counting the number of missing values in a dataset. It takes a numeric variable as an argument and returns the number of missing values. For example, NMISS (VAR1) would return the number of missing values in VAR1. It is commonly used for descriptive data analysis and data cleaning tasks.


You can use the NMISS function in SAS to count the number of missing values for each numeric variable in a dataset.

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

proc means data=my_data nmiss;
run;

This particular example will count the number of missing values for each numeric variable in the dataset called my_data.

The following example shows how to use NMISS in practice.

Example: Use NMISS in SAS to Count Number of Missing Values for Each Numeric Variable

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 rebounds;
    datalines;
A 10 2 .
A 17 5 .
A 17 . .
A 18 3 4
A 15 0 5
B . 4 5
B 29 0 8
B . 2 9
C 12 1 9
. 30 1 .
;
run;

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

Notice that there are missing values for each variable in the dataset.

We can use the NMISS function to count the number of missing values in each variable:

/*count number of missing values in each variable*/
proc means data=my_data nmiss;
run;

NMISS function in SAS example

From the output table we can see:

  • The points variable has 2 missing values.
  • The assists variable has 1 missing value.
  • The rebounds variable has 4 missing values.

And so on.

By default, the NMISS function does not count the number of missing values for character variables in a dataset.

/*count number of missing values for team variable*/
proc sql; 
    select nmiss(team) as missing_team_values
    from my_data;
quit;

From the output we can see that there is 1 missing value in the team column.

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

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

x