BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
c_starfish
Calcite | Level 5

Hello, 

I am dealing with data where I have subject IDs and a variable that tells me the diseases each subject has. Some of the subjects have more than one disease but they are just inputted in the dataset multiple times. For example: 

 

data example;

input ID condition$ ;

datalines; 

45 diabetes

46 cancer

46 diabetes 

47 cancer 

 

 

What I want is a summary of the frequency of conditions. For example, X number of people have only one condition but Y number of people have two conditions and Z number of people have three conditions, etc. I am thinking that I would just like to create a variable that tells me the number of conditions each participant has but I am not sure how to do this. 

 

Is there a way I can do this? 

1 ACCEPTED SOLUTION

Accepted Solutions
error_prone
Barite | Level 11

Use proc summary to get the number of conditions each patient has, then pro freq to get the required output.

proc summary data=example nway;
   class id;
   output out=CondById(drop=_type_ rename=(_freq_=NumConditions));
run;


proc freq data=CondById noprint;
   tables NumConditions / out=FreqCond(drop=percent);
run;

 

View solution in original post

3 REPLIES 3
Reeza
Super User

Is a patient going to have multiple diagnosis entries for the same event, ie will diabetes be there twice?

 

If not, you can use a PROC FREQ to get the number of counts. Otherwise, you're looking to count distinct. 

 

I just posted a solution on how to count distinct items per group here:

 

https://communities.sas.com/t5/SAS-Statistical-Procedures/Count-unique-variables-associated-with-one...

error_prone
Barite | Level 11

Use proc summary to get the number of conditions each patient has, then pro freq to get the required output.

proc summary data=example nway;
   class id;
   output out=CondById(drop=_type_ rename=(_freq_=NumConditions));
run;


proc freq data=CondById noprint;
   tables NumConditions / out=FreqCond(drop=percent);
run;

 

c_starfish
Calcite | Level 5

Hey thank you so much! what an easy solution to my problem. You rock! 

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3 replies
  • 2004 views
  • 0 likes
  • 3 in conversation