I have a large data set with admission dates and discharge dates.
There is one unique field value we can call Uniq1.
Other fields can be called MId, DxCD, DxDl, PrId, PrDl, PsId, PsDl.
Uniq1, MId, DxCD, PrId, PsId are Integer.
Each record has a Uniq1.
What I need to do is output a dataset (thinking SelfJoin) from this dataset that has flagged each record with a yes or no, (1 or 0), where a 1 = a record whose discharge date is followed by another record’s admission date within 30 days of the discharge date.
This would be specific to the MId, so that if MId 1 had 6 records chronologically and the second record was an admission within 30 days of the previous record’s discharge date the second record would be flagged = 1 while the initial record would be flagged 0 and among the 4 subsequent records for MId 1 there are no other similar 30 day occurrences, so they are flagged = 0 as well.
Ideally, I would like the following output, for example:
Uniq1 MId Admit Disch #Days 30DyReAdFLG PrDl, PsDl
123 1 1/24/2010 2/4/2010 0 CharValue CharValue
321 1 2/25/2010 3/5/2010 21 1 CharValue CharValue
789 1 6/21/2010 6/28/2012 116 0 CharValue CharValue
Notice that the # days between Uniq1-123 and Uniq1-321 are21 and therefore flag =1, however, between Uniq1-321 and Uniq1-789 the # of days are 116 and the flag = 0.
Any advice would be most appreciated, thank you