Dear team member,
Thanks for your post. Thanks for this approach. I can use proc sql to do get what I want. How about proc sort nodupkey approach?
Thanks,
blueblue
@GN0001 IF you would have posted sample data with the date variable containing a proper SAS date value then I assume the discussion here would have been much shorter/quicker.
IF you've got a date variable that sorts properly then a double Proc Sort is one way to go.
The first Proc Sort to order your data with the newest date per member id on top, the 2nd Proc Sort with a NODUPKEY to then pick the first row per member id (same that what a data step if first.member_id would do).
data have;
input MemberID $ date1:ddmmyy10.;
format date1 date9.;
datalines;
1 04/02/2021
1 04/03/2021
1 05/03/2019
;
proc sort data=have out=want;
by MemberID DESCENDING date1;
run;
proc sort nodupkey out=want;
by MemberID;
run;
@GN0001 wrote:
Hello Patrick,
Something came to my mind. If memberId are same but observations are different across rows, then what happens?
Thanks for your input,
Blueblue
Once again: try it.
Especially test PROC SORT with the NODUPKEY vs. the NODUPREC options.
Using the double SORT may not work under certain circumstances (SPDE datasets, for example).
After the ascending sort, do
data want;
set have;
by id;
if last.id;
run;
Kurt,
Can you please explain about this?
thanks
Blue blue
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.