BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
RoseRahman
Calcite | Level 5
IDICD1ICD2ICD3ICD4ICD5
1001808.1201101.9003922
1002421.0556707.3997
1003787.2308599.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.

1 ACCEPTED SOLUTION

Accepted Solutions
Steelers_In_DC
Barite | Level 11

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;

View solution in original post

3 REPLIES 3
ballardw
Super User

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.

Steelers_In_DC
Barite | Level 11

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;

RoseRahman
Calcite | Level 5

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;

sas-innovate-2024.png

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.

 

Register now!

How to choose a machine learning algorithm

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.

Discussion stats
  • 3 replies
  • 4120 views
  • 2 likes
  • 3 in conversation