I have the following data:
PATIENT|CLIENT |START_DATE |END_DATE |CHECKLIST |PLAN
19993 7499 2017-08-18 2018-08-19 1 ZFD
19994 5994 2017-04-17 2018-04-18 1 ZRLZG
19994 5994 2017-04-17 2018-04-18 2 ZRLZG
19994 5994 2017-06-14 2018-06-15 1 ZRLZG
19994 5994 2017-06-14 2018-06-15 2 ZRLZG
19994 5994 2018-05-31 2018-06-02 1 CZMRZDCB
19994 5994 2018-05-31 2019-06-01 1 ZRLZG
19994 5994 2018-05-31 2019-06-01 2 ZRLZG
How can I add a new boolean column that tells me if a plan, for a given patient/client combination, is renewed? By renewed I specifically mean, for a given Row A, if there is any other Row B with the same patient/client/plan that has a Row B Start to Row B End that overlaps with Row A's End.
In this case, the desired output would be:
PATIENT|CLIENT |START_DATE |END_DATE |CHECKLIST |PLAN |RENEWED
19993 7499 2017-08-18 2018-08-19 1 ZFD FALSE
19994 5994 2017-04-17 2018-04-18 1 ZRLZG TRUE
19994 5994 2017-04-17 2018-04-18 2 ZRLZG TRUE
19994 5994 2017-06-14 2018-06-15 1 ZRLZG TRUE
19994 5994 2017-06-14 2018-06-15 2 ZRLZG TRUE
19994 5994 2018-05-31 2018-06-02 1 CZMRZDCB FALSE
19994 5994 2018-05-31 2019-06-01 1 ZRLZG FALSE
19994 5994 2018-05-31 2019-06-01 2 ZRLZG FALSE
Hoping to do this in one Partition command if possible.
Update: Seeing the proposed solutions I realize I oversimplified the situation by not showing the field CHECKLIST which poses an issue to lead/lag. I still only care about renewed plans and not anything w/r/t checklist, but using lead/lag could compare to another checklist in the same plan which I want to avoid.