You can use the following methods to count the number of missing values in SAS:
Method 1: Count Missing Values for Numeric Variables
proc means data=my_data
NMISS;
run;
Method 2: Count Missing values for Character Variables
proc sql;
select nmiss(char1) as char1_miss, nmiss(char2) as char2_miss
from my_data;
quit;
The following examples show how to use each method in practice with the following dataset in SAS:
/*create dataset*/
data my_data;
input team $ pos $ rebounds assists;
datalines;
A G 10 8
B F 4 .
. F 7 10
D C . 14
E F . 10
F G 12 7
G C . 11
;
run;
/*view dataset*/
proc print data=my_data;
Example 1: Count Missing Values for Numeric Variables
We can use the following code to count the number of missing values for each of the numeric variables in the dataset:
/*count missing values for each numeric variable*/
proc means data=my_data
NMISS;
run;
From the output we can see:
- There are 3 total missing values in the rebounds column.
- There is 1 total missing value in the assists column.
Example 2: Count Missing Values for Character Variables
We can use the following code to count the number of missing values for each of the character variables in the dataset:
/*count missing for each character variable*/
proc sql;
select nmiss(team) as team_miss, nmiss(pos) as pos_miss
from my_data;
quit;
From the output we can see:
- There is 1 missing value in the team column.
- There are 0 missing values in the pos column.
Note: You can find the complete documentation for the NMISS function here.
Additional Resources
The following tutorials explain how to perform other common tasks in SAS:
How to Normalize Data in SAS
How to Remove Duplicates in SAS
How to Replace Missing Values with Zero in SAS