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?
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;
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:
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;
Hey thank you so much! what an easy solution to my problem. You rock!
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.