I have a data similar to this and I want to select the last visit for each individual. How would I do that?
ID
visit
1
5/3/20
7/2/20
2
8/9/21
3
1/5/20
4/18/20
8/23/20
4
6/8/20
10/9/20
I want an output like this (I don’t want to include those that have only one visit)
Assuming VISIT is a numeric sas date variable then do:
proc sort data=jave; by ID visit; run; data want; set have; by ID visit; if last.ID; run;
View solution in original post
Since the request included "(I don’t want to include those that have only one visit)", I propose the below modification to @Shmuel's solution
proc sort data=have; by ID visit; run; data want; set have; by ID visit; if last.ID and not(first.id); run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Save the date!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.