I added a true date column in your test data: data test; input year month a $ count; format dt date9.; dt = mdy(month,1,year); cards; 2012 1 aa 160 2012 1 bb 260 2012 2 aa 760 2012 2 bb 860 2012 3 aa 260 2012 3 bb 960 2012 4 aa 760 2012 4 bb 660 2012 5 aa 560 2012 5 bb 660 2012 6 aa 460 2012 6 bb 460 2012 7 aa 360 2012 7 bb 260 2012 8 aa 260 2012 8 bb 960 2012 9 aa 160 2012 9 bb 860 2012 10 aa 575 2012 10 bb 775 2012 11 aa 690 2012 11 bb 390 2012 12 aa 760 2012 12 bb 560 2013 1 aa 490 2013 1 bb 290 2013 2 aa 809 2013 2 bb 709 2013 3 aa 609 2013 3 bb 309 ; run; proc sql; select case when t1.dt = t2.curr_dt then 'Current' when t1.dt > intnx('month',t2.curr_dt,-13) then 'Prior Rolling 12 Months' end as Period ,count(*) as Obs ,avg(count) as Mean_Count ,min(count) as Min_Count ,max(count) as Max_Count from test t1, (select max(dt) format=date9. as curr_dt from test) t2 where calculated period is not null group by calculated period ; quit; produces this dataset: Current 2 459 309 609 Prior Rolling 12 Months 24 570.3333 160 960
... View more