data have;
infile datalines truncover;
input Acct_Nbr Cont_Mnth :$7. expected_6_mons_con $;
cont_date=input(cont_mnth||'/01',yymmdd12.);
format cont_date date9. ;
datalines;
123456 2022/01 Y
123456 2022/02
123456 2022/03
123456 2022/04
123456 2022/05
123456 2022/06
234567 2022/01 N
234567 2022/02
234567 2022/04
234567 2022/07 Y
234567 2022/08
234567 2022/09
234567 2022/10
234567 2022/11
234567 2022/12
345678 2021/10 Y
345678 2021/11
345678 2021/12
345678 2022/03
345678 2022/04
345678 2022/05
;
run;
proc sql;
create table want as
select *,case when
(select count(distinct cont_date) from have
where Acct_Nbr=a.Acct_Nbr and cont_date between a.cont_date and intnx('month',a.cont_date,5))
=6 then 'Y'
else 'N' end as want
from have as a;
quit;
... View more