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
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.