BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
BTAinRVA
Quartz | Level 8

Hello Everybody!

 

I've got a data set and I'm trying to create a variable that will flag the last Encounter_Date for each patient for each fiscal month/fiscal year. They may have multiple encounters on the last Encounter_Date. I'm trying to replicate the results of this code:

 

proc sql;

create table bbb as select * from aaa

group by fy, fm, ppid

 having encounter_date = max(encounter_date);

quit;

 

with something like this (I want to keep all records in aaa and flag the max(encounter_date)):

 

proc sort data = aaa;

by FY FM ppid encounter_date;

run;

 

data bbb;

 

set aaa;

by FY FM ppid;

if last.ppid then Max_Enc_Date = 1 ;

else Max_Enc_Date =0 ;

run;

 

Thanks,

Brian

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

To keep several observations, all with the same maximum date, sort in descending order:

 

proc sort data=aaa;

by fy fm ppid descending encounter_date;

run;

 

Then it is easy to select all those having the maximum:

 

data want;

set have;

by fy fm ppid;

if first.ppid then max_date = encounter_date;

retain max_date;

Max_Enc_Date = (encounter_date = max_date);

drop max_date;

run;

View solution in original post

2 REPLIES 2
Astounding
PROC Star

To keep several observations, all with the same maximum date, sort in descending order:

 

proc sort data=aaa;

by fy fm ppid descending encounter_date;

run;

 

Then it is easy to select all those having the maximum:

 

data want;

set have;

by fy fm ppid;

if first.ppid then max_date = encounter_date;

retain max_date;

Max_Enc_Date = (encounter_date = max_date);

drop max_date;

run;

BTAinRVA
Quartz | Level 8

That's Astounding!

 

Thank you!

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 2 replies
  • 834 views
  • 0 likes
  • 2 in conversation