data covg_overlap_flag_2019; set covg_rec_2019_sorted (keep=POIDS); by POIDS; merge covg_rec_2019_sorted covg_rec_2019_sorted (firstobs=2 keep=BNFT_CVG_EFFECTIVE_DT BNFT_CVG_TERM_DT rename=(BNFT_CVG_EFFECTIVE_DT=next_sd) rename=(BNFT_CVG_TERM_DT=next_ed)); if (first.POIDS=0 and BNFT_CVG_EFFECTIVE_DT<lag(BNFT_CVG_TERM_DT)) or (BNFT_CVG_TERM_DT>next_sd and last.POIDS=0) then flag+1; else if (first.POIDS=0 and BNFT_CVG_EFFECTIVE_DT=lag(BNFT_CVG_EFFECTIVE_DT)) or (first.POIDS=0 and BNFT_CVG_TERM_DT=lag(BNFT_CVG_TERM_DT)) then flag+1; else if (last.POIDS=0 and BNFT_CVG_EFFECTIVE_DT=next_sd) or (BNFT_CVG_TERM_DT=next_ed and last.POIDS=0) then flag+1; else flag=0; run;
... View more