BookmarkSubscribeRSS Feed
csantia
Calcite | Level 5

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!

2 REPLIES 2
ballardw
Super User

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.

 

 

mkeintz
PROC Star

Please provide sample data of what you HAVE and what you WANT.  You'll get much better results.  

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

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

Creating Custom Steps in SAS Studio

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 1132 views
  • 1 like
  • 3 in conversation