SAS Community,
I am trying to solve a merging problem. Data set Have1 is a table with hospital admission and discharge dates. Have2 is a table of outpatient office visit dates.
What I want to do, is merge the two in such a way:
For each row where a person/discharge date on Have1, join the date of the first subsequent office visit from Have2. A patient may have several, but I just want to add the first.
A second component that is a bit tricky, is if a person is readmitted to the hospital before they have an outpatient office visit, then the Soonest Follow Up_ Office Visit Date should be left blank, and a flag for readmission set to "Y". In the example below, the patient was discharged on Sept 3. The first subsequent office visit was on Sep 20, however an admission occured prior to this office visit on Sept 5. So in this case I don't want to populate the Soonest Follow Up field, since the person didn't follow up because they were back in the hospital.
Any help is greatly appreciated. Thank you.
Have 1
Person
Admit _date
Discharge Date
A
30APR2015
01MAY2015
A
02SEPT2015
03SEPT2015
A
05SEPT2015
07SEPT2015
A
11NOV2015
12NOV2015
A
19DEC2015
21DEC2015
Have 2
Person
Office Visit Date
A
01JAN2015
A
02JUNE2015
A
15JUL2015
A
20SEPT2015
A
20NOV2015
A
05DEC2015
Want
Person
Admit _date
Discharge Date
Soonest Follow Up_ Office Visit Date
Admitted Prior to Office Visit
A
30APR2015
01MAY2015
02JUNE2015
N
/*June 2 was the first office visit that occurred after this discharge*/
A
02SEPT2015
03SEPT2015
Y
/*The patient was readmitted before the first most recent office visit. No date populated, admitted flag set to Y*/
A
05SEPT2015
07SEPT2015
20SEPT2015
N
/*Sept 20 was the first office visit that occurred after this discharge*/
A
11NOV2015
12NOV2015
20NOV2015
N
/*Nov 20 was the fist office visit that occurred after this discharge*/
A
19DEC2015
21DEC2015
N
/*no office visits had a date that was after this discharge. Value is left blank*/
... View more