Hi guys,
suppose to have the following dataset:
data DB;
input ID :$20. Admission :date09. Discharge :date09. Index age age_class;
format Admission date9. Discharge date9.;
cards;
0001 13JAN2017 25JAN2017 1 59 6
0001 22FEB2018 03MAR2018 0 60 6
0001 30JAN2019 04MAR2019 0 61 7
0002 01DEC2016 14DEC2016 0 67 7
0002 01DEC2016 14DEC2016 0 67 7
0002 25DEC2017 02JAN2018 1 68 7
0002 25FEB2018 27FEB2018 0 69 7
0003 09JAN2016 25JAN2016 0 34 4
0003 29JAN2018 12FEB2018 1 36 4
0004 02FEB2014 12MAR2014 1 76 8
0004 04APR2018 11APR2019 0 80 8
0004 02DEC2018 11SEP2019 0 80 8
;run;
Is there a way to get the following?
data DB1;
input ID :$20. Admission :date09. Discharge :date09. Index age age_class;
format Admission date9. Discharge date9.;
cards;
0001 13JAN2017 25JAN2017 1 59 6
0001 22FEB2018 03MAR2018 0 59 6
0001 30JAN2019 04MAR2019 0 59 6
0002 01DEC2016 14DEC2016 0 0 0
0002 01DEC2016 14DEC2016 0 0 0
0002 25DEC2017 02JAN2018 1 68 7
0002 25FEB2018 27FEB2018 0 68 7
0003 09JAN2016 25JAN2016 0 0 0
0003 29JAN2018 12FEB2018 1 36 4
0004 02FEB2014 12MAR2014 1 76 8
0004 02FEB2014 12MAR2014 0 0 0
0004 04APR2018 11APR2019 0 76 8
0004 02DEC2018 11SEP2019 0 76 8
;run;
Rules:
1) For all cases like 0001, format age and age_class variables based on what is reported at Index = 1.
2) For all cases like 0002 do the same as for 0001 with the following exception: set to 0 the two variables (age and age_class ) if dates < dates at Index = 1. This should be done in the case dates are identical like in this case ( 01DEC2016 14DEC2016 ) or not.
3) For all cases like 0003 do the same as for 0002.
4) For all cases like 0004: do the same as for 0001 but in this case dates are replicated but in one case Index = 1 and in the other Index = 0. When Index = 0 and dates are replicated, then set the two variables, age and age_class, to 0.
Can anyone help me please?
... View more