BookmarkSubscribeRSS Feed
cbatzi01
Calcite | Level 5

Hi,

 

I have a data set that contains Patient IDs, Drugs, and date of the prescription fill.  I am trying to identify the number of individual patients that were on a drug in a given year.  A patients typically have multiple records within a year, as each record representation a prescription fill date.  The data structure looks like this:

 

PatidDrugNameYear
100Drug 12013
200Drug 12013
200Drug 12013
200Drug 12013
200Drug 12013
300Drug 12013
100Drug 12014
300Drug 22013
100Drug 22015
400Drug 22015
400Drug 22015
400Drug 22015
300Drug 32014
300Drug 32015
100Drug 32015

 

 

In my head, the output should should look something like this:

Drugyear#Patients
Drug 120133
Drug 120141
Drug 220131
Drug 220151
Drug 320141
Drug 320152

 

 

I have tried proc summary, but that just gives me a frequency of the number of records, by drug & year.  I am thinking proc sql using count/distinct would work, but not sure how to group by drugname & year, as I am not very good at this...

 

Any assistance is greatly appreciated.


Thanks!
Chris

 

3 REPLIES 3
Reeza
Super User

You can do that but I'd consider a different method because you are likely to want multiple stats.

 

data have2;
set have;

by id drug;
First_Drug=0;
if first.drug then First_Drug=1;

run;

proc means data=have2 sum;
class year drug;
var first_drug;
output out=want sum(first_drug) = num_patients;
run;
cbatzi01
Calcite | Level 5

Thanks.  This worked well, and matches up with another step in my analysis. 

 

-Chris

 

Astounding
PROC Star

PROC FREQ is pretty good at counting:

 

proc freq data=have;

tables DrugName*PatID*Year / noprint out=summarized;

run;

 

proc freq data=summarized;

tables DrugName*Year / list;

run;

 

The frequency column in the final PROC FREQ will be the patient count.  Also note, the second PROC FREQ could create an output data set if needed.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 3147 views
  • 0 likes
  • 3 in conversation