Hi guys,
suppose to have the following:
data DB;
input ID :$20. Admission :date09. Discharge :date09. Index Age_class;
format Admission date9. Discharge date9.;
cards;
0001 13JAN2015 20JAN2015 1 6
0001 21FEB2015 31DEC2015 0 6
0001 01MAR2018 30SEP2018 0 7
0001 01JAN2019 31DEC2019 0 7
0002 01JAN2015 31DEC2015 1 3
0002 01JAN2019 31OCT2019 0 5
0003 08FEB2014 10MAR2014 1 3
0003 16JUN2015 13JUL2015 0 3
0004 04MAY2016 10MAY2016 1 8
0004 13SEP2017 15NOV2017 0 8
0004 09DEC2018 31DEC2018 0 8
;
Age_class takes values from 1 to 8.
Is there a way to get the following?
data DB;
input ID :$20. Admission :date09. Discharge :date09. Index Age_class Age_class1 Age_class2 Age_class3 .... Age_class7 Age_class8;
format Admission date9. Discharge date9.;
cards;
0001 13JAN2015 20JAN2015 1 6 1 1 1 ... 1 1
0001 21FEB2015 31DEC2015 0 6 0 0 0 ... 0 0
0001 01MAR2018 30SEP2018 0 7 0 0 0 ... 0 0
0001 01JAN2019 31DEC2019 0 7 0 0 0 ... 0 0
0002 01JAN2015 31DEC2015 1 3 1 1 0 ... 1 1
0002 01JAN2019 31OCT2019 0 5 0 0 0 ... 0 0
0003 08FEB2014 10MAR2014 1 3 1 1 0 ... 1 1
0003 16JUN2015 13JUL2015 0 3 0 0 0 ... 0 0
0004 04MAY2016 10MAY2016 1 8 1 1 1 ... 1 0
0004 13SEP2017 15NOV2017 0 8 0 0 0 ... 0 0
0004 09DEC2018 31DEC2018 0 8 0 0 0 ... 0 0
;
In other words I need to fill Age_class* variables (Age_class1, Age_class2, ..., Age_class8) with 1 if at Index = 1 the patient IS NOT in that age_class and 0 otherwise.
Note that Index = 1 is always the first date (Admission-Discharge) for each patient and there is always one Index = 1 for each patient.
For example: pts 0001 at Index = 1 has Age_class = 6. Age_class1, Age_class2, Age_class3, Age_class4, Age_class5, Age_class7, Age_class8 will be filled with 1 because the patient is not contributing to that age_class while it will be 0 at Age_class6 because it is contributing.
Note also, that there are other dates that will be put to 0 because of no interest.
I know, I can do "if then else" but it will take a lot of coding to perform all comparisons.
Thank you very much for your help.
... View more