I have two datasets and I need to merge them together. These datasets will require a many to many merge. One is a healthcare visit dataset and the other is a medication pick-up dataset. Two of the variables I need to merge on are a patient id and provider id and then I also need to merge on a visit date. However I do not need the visit date to be the same, I need it to be either on the same day or within the following X amount of days (7 for example). I am not sure how I can merge two datasets on an inexact but specified timeframe rather than a single variable. Is there a way to do this? Is there another approach for this outside of also merging on date?
Thank you!
Not much detail to go on, no data set names, no variable names.
You can select with something like this, assuming your date values are actually SAS date values:
JOIN ON basedate le desireddate le intnx('days',basedate,7)
if you want a desired date variable to between some other date variable and 7 days later. SAS dates you could actually just use (basedate+7) but the intnx function would be the way to increment another date by week, month, quarter or year with some others mixed in.
This would be done in Proc SQL to get reliable many-to-many join.
Likely you would have aliases indicating which dataset each of your date variables comes from.
I think you likely would be using the provider visit date as "basedate" and the medication date as the "desireddate" above.
Please provide sample data of what you HAVE and what you WANT. You'll get much better results.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.