Hi, In answer to your initial post, it should be real easy to get the cumulative average: data have; attrib month format=$20. month_id value format=best.; infile datalines delimiter=","; input month $ month_id value; datalines; jan,1,45 feb,2,32 mar,3,67 apr,4,34 ; run; proc sql; create table WANT as select A.*, (select SUM(VALUE) from WORK.HAVE where MONTH_ID <= A.MONTH_ID) / (select COUNT(MONTH) from WORK.HAVE where MONTH_ID <= A.MONTH_ID) as CUMULATIVE_AVG from HAVE A; quit; In answer to your latest post (which I just posted on the other post), with the groupings: data have; attrib id time_period income format=best.; infile datalines delimiter=","; input id time_period income; datalines; 1,1,45 1,2,32 1,3,67 1,4,34 2,1,23 2,2,89 2,3,78 2,4,10 ; run; proc sql; create table WANT as select A.*, (select SUM(INCOME) from WORK.HAVE where ID=A.ID and TIME_PERIOD <= A.TIME_PERIOD) as TOTAL, CALCULATED TOTAL / (select COUNT(ID) from WORK.HAVE where ID=A.ID and TIME_PERIOD <= A.TIME_PERIOD) as CUMULATIVE_AVG from HAVE A; quit;
... View more