data have;
input id Cd $ flg $ DATE DATE9.;
format date date9.;
datalines;
11 chg b 13apr2019
11 chg i 11apr2019 /*show*/
11 chg e 6apr2019 /*show*/
11 chg b 5apr2019
11 add d 4apr2019 /*show*/
11 chg y 1apr2019
;run;
I want to select the last instance of the ( flg = d or 11 add d 4apr2019)
I want to select the first instance after the row moved from a flg = d to an e or 11 chg e 6apr2019)
I want to then select the first instance where the row moved from the flg = e to something else. So in this case I want to show 11 chg i 11apr2019