Hi guys,
suppose to have the following dataset:
data have;
input ID :$20. Admission :date09. Discharge :date09.;
format Admission date9. Discharge date9.;
cards;
0001 13JAN2015 20JAN2015
0001 21FEB2015 31DEC2015
0001 01MAR2018 30SEP2018
0001 01JAN2019 31DEC2019
0002 01JAN2015 31DEC2015
0002 01JAN2019 31OCT2019
0002 01NOV2019 31DEC2020
;
I need to add a variable indicating the year of admission from start of February of one year to the end of January of the next year starting from 2015 and ending to 2021. All happening before will be set to 0. The desired output should be:
data db;
input ID :$20. Admission :date09. Discharge :date09. year;
format Admission date9. Discharge date9.;
cards;
0001 13JAN2015 20JAN2015 0
0001 21FEB2015 31DEC2015 2015
0001 01MAR2018 30SEP2018 2018
0001 01JAN2019 31DEC2019 2018
0002 01JAN2015 31DEC2015 0
0002 01JAN2019 31OCT2019 2018
0002 01NOV2019 31DEC2020 2019
;
In other words since the admission of 0001 on 13JAN2015 happens before February 2015 (start), the variable takes value 0. The same for ID 0002 on 01JAN2015.
Note that only admission date will be taken into consideration for the evaluation.
Thank you in advance