ID | ICD1 | ICD2 | ICD3 | ICD4 | ICD5 |
---|---|---|---|---|---|
1001 | 808.1 | 201 | 101.9 | 003 | 922 |
1002 | 421.0 | 556 | 707.3 | 997 | |
1003 | 787.2 | 308 | 599.8 |
I have 5 ICD codes in 5 columns, they are character variables. I want to be able to count how many valid values each subject has in the 5 ICD columns. So, for 1001, the result would be 5, for 1002 it will be 4 and 1003 will be 3. Or we could see it as the number of missing values in an array of variables per subject. Thank you.
for character variables you would use the function cmiss().
For count of not missing:
data want;
set have;
valid = 5 - cmiss(of icd1-icd5);
run;
or for count of missing:
data want;
set have;
valid = cmiss(of icd1-icd5);
run;
in a data step:
data want;
set have;
numvalid = n( of ICD1-icd5);
run;
The function NMISS with the same basic syntax would give the missing per record.
for character variables you would use the function cmiss().
For count of not missing:
data want;
set have;
valid = 5 - cmiss(of icd1-icd5);
run;
or for count of missing:
data want;
set have;
valid = cmiss(of icd1-icd5);
run;
This works! Thank you! I also tried the longer method that seems to work.
array _icdvar ICD1-ICD5;
cnticd=0;
do i=1 to 5;
if missing(_icdvar(i)) = 0 then cnticd=cnticd+1;
end;
drop i;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Use this tutorial as a handy guide to weigh the pros and cons of these commonly used machine learning algorithms.
Find more tutorials on the SAS Users YouTube channel.