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;