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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: