Hello
I want to calculate number of numeric missing values in each row.
I want to calculate number of Char missing values in each row.
Why the char missing values is not calculated correctly??
data my_data;
input team $ points assists rebounds;
cards;
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;
data want;
set my_data;
nr_Numeric_Missing_Values=nmiss(of _numeric_)-1;
nr_CHAR_Missing_Values=nmiss(of _character_)-1;
Run;
I'm not sure why you're subtracting 1 from these. For one thing, both of the variables you're creating are numeric, so I don't see a reason to subtract 1 from the count of character missing values. Second, neither of these two new variables would have missing values in the first place, so they wouldn't be contributing to the count of missing values.
Oh, also, you need to use cmiss() for the 2nd one.
Why are you using nmiss to calculate nr_CHAR_Missing_Values?
Why are you subtracting 1 from the result?
The NMISS function is used to count numeric missing values only. It does not work for character variables.
CMISS works for both numeric and character variables.
If you use the cmiss instead of nmiss function then your code will execute without errors but it will return -1 for nr_CHAR_Missing_Values.
The answers you've got here explain why you need to subtract 1. ...and now ask yourself of what datatype nr_CHAR_Missing_Values is and you should understand how to fix your code.
@quickbluefish wrote:
Oh, interesting - because the numeric count variable is initially missing itself. Got it.
Or in this case numeric count variables
Because NMISS() is only worked for NUMERIC type variable, NOT CHARACTER type variable.
If you want to take into account of both of them , switch into CMISS().
data my_data; input team $ points assists rebounds; cards; 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; data want; set my_data; nr_Numeric_Missing_Values=0; nr_CHAR_Missing_Values=0; nr_Numeric_Missing_Values=cmiss(of _numeric_); nr_CHAR_Missing_Values=cmiss(of _character_); Run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.