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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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