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;
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.
However, we can use the following workaround with PROC SQL to count the number of missing values for the character variable called team:
/*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 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