SQL is not the proper tool to do sequential operations such as cumulative sums. Use a datastep instead, it will be simpler and much faster. data have; input ID Year Month Value; datalines; 12345 2013 5 -94.32 12345 2013 6 19.82 12345 2013 7 55.49 12345 2013 8 28.73 12345 2013 9 -24.6 12345 2013 10 -36.4 ; proc sort data=have; by id year month; run; data want; set have; by id; if first.id or sum>0 then sum=0; sum + value; run; proc print data=want noobs; run; PG
... View more