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
Opal | Level 21

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 2024

Innovate_SAS_Blue.png

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. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

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