Hi guys,
suppose to have the following two datasets:
The first one contains a full list of dates per ID and an index that indicates if the patient has a comorbidity (1) or not (0). Then, there's another dataset that contains a subset of dates from the first dataset and a RefDate, 1 or 0. What I would like to do is the following:
for each ID:
- if the comorbidity in DB1 = 1(!) before or = to the Start_Therapy where in DB2 RefDate = 1 then add an Index in DB1 equal to 1 otherwise the Index should be 0 regardless if in DB1 the comorbidity = 1.
- if the comorbidity in DB1 = 0 it should remain 0.
Thank you in advance!
Desired output = DB3
data DB1;
input ID Start_Therapy Comorbidity;
format Start_Therapy date9.;
cards;
0001 01OCT2015 1
0001 06DEC2016 1
0001 08NOV2020 1
0002 11JAN2014 0
0002 16JUN2014 0
0002 14MAY2015 1
0002 30JUN2015 1
0002 25FEB2016 0
0003 11SEP2012 0
0003 24AUG2014 1
0003 10DEC2014 1
0004 03JAN2014 0
0004 09FEB2014 1
0004 03AUG2015 1
0004 18MAY2016 0
;
data DB2;
input ID Start_Therapy RefDate;
format Start_Therapy date9.;
cards;
0001 06DEC2016 1
0001 08NOV2020 0
0002 16JUN2014 1
0002 30JUN2015 0
0003 24AUG2014 1
0003 10DEC2014 0
0004 03AUG2015 1
;
data DB3;
input ID Start_Therapy Comorbidity Index;
format Start_Therapy date9.;
cards;
0001 01OCT2015 1 1
0001 06DEC2016 1 1
0001 08NOV2020 1 0
0002 11JAN2014 0 1
0002 16JUN2014 0 1
0002 14MAY2015 1 0
0002 30JUN2015 1 0
0002 25FEB2016 0 0
0003 11SEP2012 0 0
0003 24AUG2014 1 1
0003 10DEC2014 1 0
0004 03JAN2014 0 0
0004 09FEB2014 1 1
0004 03AUG2015 1 1
0004 18MAY2016 0 0
;