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;

Develop Code with SAS Studio

Get started using SAS Studio to write, run and debug your SAS programs.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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