BookmarkSubscribeRSS Feed
cbatzi01
Calcite | Level 5

Hi, 

 

I have pharmacy claims data.  I would like to keep the first record for each patient and each drug based on fill date. My data look like this: 

 

Patid Drug Fill_date

 

 Normally, if I was interested in only 1 drug, i would only keep those records, and then  I would sort by patid and fill_date, then do something like this: 

 

proc sort data=have; by patid drug fill_date; run;

data want; 

data have;

by patid

if first.patid=1;

run;

 

But since I need the first patid AND drug, that will not work.  How would this be done if I sorted by patid, drug, and fill_date?

 

Thanks!
Chris

 

3 REPLIES 3
Reeza
Super User

You want each each new instance of drug in this case, so change your FIRST to be relative to the drug variable.

 

if first.drug;

Make sure your BY statement has at least both variables.

 

 

cbatzi01
Calcite | Level 5

Sorry, I need the first of the drug for each unique patient ID.  Does your method still work with that requirement? 

 

Thanks!
Chris

 

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 850 views
  • 0 likes
  • 2 in conversation