I have dataset which has 3 variables which includes ID, date and enrol, and it is sorted by ID and date. My goal is to create a new dataset which has another variable say enrol_flag which should be 1 once the enrol is 1 but it should become 0 once enrol is 0 and retains that 0 value.
I am using SAS to program.
My dataset looks like:
ID Date enrol
1 01JAN21 0
1 O1FEB21 1
1 01MAR21 1
1 01APR21 1
1 01MAY21 0
1 01JUN21 0
1 01JUL21 1
1 01AUG21 1
2 01JAN21 1
2 O1FEB21 1
2 01MAR21 1
2 01APR21 1
2 01MAY21 1
2 01JUN21 0
2 01JUL21 0
2 01AUG21 0
3 O1FEB21 0
3 01MAR21 0
3 01APR21 0
3 01MAY21 0
3 01JUN21 0
3 01JUL21 1
Output I want
ID Date enrol enrol_flag
1 01JAN21 0 0
1 O1FEB21 1 1
1 01MAR21 1 1
1 01APR21 1 1
1 01MAY21 0 0
1 01JUN21 0 0
1 01JUL21 1 0
1 01AUG21 1 0
2 01JAN21 1 1
2 O1FEB21 1 1
2 01MAR21 1 1
2 01APR21 1 1
2 01MAY21 1 1
2 01JUN21 0 0
2 01JUL21 0 0
2 01AUG21 0 0
3 O1FEB21 0 0
3 01MAR21 0 0
3 01APR21 0 0
3 01MAY21 0 0
3 01JUN21 0 0
3 01JUL21 1 1
Thank you in advance for your help.
Try this