Here is the modified code and I also put comments there for your easier reading. I am afraid you are not only doing the cummalative calculation for all of the observations of one variable. If you need to calculate the cumm for each category of this variable, you have to put this variable before year in all the 'by' statements and change if _n_ = 1 to if first.category_variable_name
Hope it helps.
/*create year var */
data yr;
do year = 1970 to 2007;
output;
end;
run;
/* create production var */
data prod;
input production@@;
cards;
100 105 110 115 120 125 130 135 140 145 150 155 160
165 170 175 180 185 190 195 200 205 210 215 220 225
230 235 240 245 250 255 260 265 270 275 280 285
;
run;
/* make up a fake dataset for the calculation */
data com;
merge yr prod;
run;
/* the following is the part you really want */
proc sort data = com; by year; run;
data com;
set com;
by year;
if _n_ = 1 then cumm = 0;
retain cumm;
cumm = sum (production, cumm);
run;
[此贴子已经被作者于2008-10-18 4:13:31编辑过]