Hi PG, I ran your code using the data OP privided. I like your code very much! Thank you! data have; input YearMonth $ Account_Number; actDate=mdy(input(substr(yearmonth,5,2),2.),1,input(substr(yearmonth,1,4),4.)); cards; 201001 1 201001 2 201002 1 201002 3 201003 4 201003 5 201004 4 201004 5 201004 6 201005 1 201005 5 201006 1 201006 5 201006 7 201006 8 201006 9 201007 5 201007 7 201008 9 201009 4 201010 10 201010 11 201011 1 201011 12 201012 7 201101 1 201102 11 201103 12 ; proc sql; create table periods as select distinct intnx("month",actDate,0,"beginning") as period format=mmyyd7., intnx("month",actDate,-11,"beginning") as periodBeg format=yymmdd10., intnx("month",actDate,0,"end") as periodEnd format=yymmdd10. from have; create table want as select period, count(distinct Account_Number) as nbCust from periods inner join have on actDate between periodBeg and periodEnd group by period; *drop table periods; select * from want; quit;
... View more