data have;
infile cards expandtabs;
input Item Sales;
cards;
1 10 30
1 10 30
1 10 30
1 10 30
1 10 30
1 10 30
1 10 20
1 10 10
2 20 60
2 20 60
2 20 60
2 20 60
2 20 60
2 20 40
2 20
;
run;
data have;
set have;
by item;
if first.item then n=0;
n+1;
run;
proc sql;
select a.*,(select sum(sales) from have where item=a.item and
n between a.n and a.n+2) as rolling_sum
from have as a;
quit;
... View more