Combination of date and flag should be used: 1. Check 5 days lag 2. If lag is within 5 days then take the first row: But here can be flag missing or not missing, If all missing, then just take the first date If some not missing, then take the not missing first flag If all not missing flag, then take the first date When as below data: data have; input id date date9. flag; format date date9.; cards; 1 1jul2021 . 1 1jul2021 . 1 4jul2021 1 1 10jul2021 4 1 16jul2021 2 1 18jul2021 1 2 1jul2021 1 2 6jul2021 . ; run; Wanted should be as below: 1 4jul2021 1 1 10jul2021 2 2 1jul2021 1 2 6jul2021 . But when as below data: data have; input id date date9. flag; format date date9.; cards; 1 1jul2021 . 1 1jul2021 . 1 4jul2022 1 1 10jul2022 4 1 16jul2022 2 1 18jul2022 1 2 1jul2021 1 2 6jul2021 . ; run; Then it should be as below: 1 1jul2021 . 1 4jul2022 1 2 1jul2021 1 2 6jul2021 .
... View more