Hi, I have a dataset with multiple categorical variables for different comorbidities of patients like arthritis, highbp, heartdisease etc. I need to create a count variable to see the exact number of comorbidities each person has. So for eg: if arthritis =1 then count =1 , then if they have heartdisease too then count should be 2 etc...
I am new to SAS can someone help me with this?
Thanks
Rashi
The answer is going to be different depending upon how your data are organized.
Post an example of your data (in the form of a datastep) and what you'd like your resulting file to look like.
Art, CEO, AnalystFinder.com
record_id arthritis hypertension heartdisease emphysema chroniclung
1 0 0 1 1 1
2 1 1 0 0 0
3 0 0 0 0 0
so record_id is each patient and these a re all the comorbidities for each patient.
I want a variable , say count which counts the exact number of comorbidities each person has
so for the record_id =1 the count should be =3(heartdisease, emphysema and chronic lung)
2 count=2
3 count=0 etc...
Thanks!
Here is one way:
data have; input record_id arthritis hypertension heartdisease emphysema chroniclung; cards; 1 0 0 1 1 1 2 1 1 0 0 0 3 0 0 0 0 0 ; data want; set have; count=countc(catt(of arthritis--chroniclung),'1'); run;
Art, CEO, AnalystFinder.com
Is there a way to do this for a large dataset where I cannot enter in all the data? Thanks!
The response from @ballardw above should work for any size data set.
And another
data want;
set have;
count = sum( of arthritis--chroniclung);
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.