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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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