I want to merge two data sets by ID and date. I want the dates in set B to be within 1 week of set A. I also want the earliest date (within 1 week) from set B to be merged to set A. Also, if there are multiple dates within 1 week, do not join multiple observations from set B to set A in a given range and ID.
What would the code look like for this? Would this be a left join if I wanted to prioritize set A?
Set A:
ID | Date |
---|---|
1 | 10-21-2021 |
2 | 03-03-2020 |
Set B:
ID | Date |
---|---|
1 | 10-22-2021 |
2 | 03-04-2020 |
1 | 10-23-2021 |
For example, the first two rows of set B would be joined to set A, but the final row would not because only one row within a week can be joined by each row in set A.