SAS (Base SAS)+
data example;
input id name $ age score;
datalines;
1 Alice 25 85
2 . 30 90
3 Charlie . 88
4 . . .
;
run;
data example2;
set example;
cmiss_subset = cmiss(name, score);
run;CMISS()is the SAS function that counts the missing values among its arguments — it accepts both numeric and character variables in the same call.cmiss_subset = cmiss(name, score);counts how many ofnameandscoreare missing on each row.- On a row where both are missing the result is 2; where only one is missing it is 1; where both are present it is 0.
CMISS()ignores the type difference betweenname(character) andscore(numeric) — no need to split the call.- For the count of non-missing values,
N(of var1 var2 ...)is the complementary function — useful for "complete n" summaries. - We run and check
example2: thecmiss_subsetvalue on each row should equal the number of missing cells amongnameandscore.