Some sample data and explanation would really improve things. Paper? Dep1? These things have meaning?
Without investing too much, I'll hazard that right now you are finding the closest date before or after and what you really want is the closest date before. I'll further hazard that a WHERE clause like "where table1.date < table2.date" might move you in that direction.
My basic approach would look something like this if I understand the rule:
proc sort data=have; by id descending day descending date2; run; data want; set have; by id ; if first.id; run;
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.