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

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

1

7/2/20

2

8/9/21

3

1/5/20

3

4/18/20

3

8/23/20

4

6/8/20

4

10/9/20

 

 

I want an output like this (I don’t want to include those that have only one visit)

ID

visit

1

7/2/20

3

8/23/20

4

10/9/20

1 ACCEPTED SOLUTION

Accepted Solutions
Shmuel
Garnet | Level 18

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

2 REPLIES 2
Shmuel
Garnet | Level 18

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;
ballardw
Super User

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-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

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!

Register now

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 2 replies
  • 1208 views
  • 4 likes
  • 3 in conversation