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 2025: Save the Date

 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!

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
  • 766 views
  • 4 likes
  • 3 in conversation