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

Hello!

 

I am currently working on performing a match-merge across four data sets. Each observation should include a unique SSN; however one dataset records four observations per one SSN. How would I go about including only the last recorded observation for each unique SSN to my final match-merged dataset?

 

The observations for the data set in question would be structured similarly to:

111-11-1111 ...

111-11-1111 ...

111-11-1111 ...

111-11-1111 ...

222-22-2222 ...

222-22-2222 ...

222-22-2222 ...

222-22-2222 ...

...

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star
proc sort data = Have;
  by SSN Visit_Date;
run;

data Want;
  set Have;
  by SSN;
  if last.SSN;
run;

View solution in original post

6 REPLIES 6
SASKiwi
PROC Star

Do you have a recorded date in your data to sort on as well as SSN? If not how would you identify the last recorded SSN?

steeleye
Fluorite | Level 6

Yes, there is a corresponding visit date for each observation. We are being asked to select the observation with the most recent visit date per SSN.

SASKiwi
PROC Star
proc sort data = Have;
  by SSN Visit_Date;
run;

data Want;
  set Have;
  by SSN;
  if last.SSN;
run;
steeleye
Fluorite | Level 6
Thank you so much, this worked perfectly!
steeleye
Fluorite | Level 6

No I'm sorry, this code is for a class so I cannot provide my code verbatim.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1943 views
  • 0 likes
  • 3 in conversation