BookmarkSubscribeRSS Feed
Rashis
Calcite | Level 5

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

6 REPLIES 6
art297
Opal | Level 21

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

 

Rashis
Calcite | Level 5

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!

art297
Opal | Level 21

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

 

joelee1
Fluorite | Level 6

Is there a way to do this for a large dataset where I cannot enter in all the data? Thanks!

PaigeMiller
Diamond | Level 26

The response from @ballardw above should work for any size data set.

--
Paige Miller
ballardw
Super User

And another

 

data want;

   set have;

   count = sum( of arthritis--chroniclung);

run;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 4472 views
  • 3 likes
  • 5 in conversation