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 ...
...
proc sort data = Have;
by SSN Visit_Date;
run;
data Want;
set Have;
by SSN;
if last.SSN;
run;
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?
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.
proc sort data = Have;
by SSN Visit_Date;
run;
data Want;
set Have;
by SSN;
if last.SSN;
run;
Can you show us your code so far?
No I'm sorry, this code is for a class so I cannot provide my code verbatim.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.