data test;
input a b;
cards;
1 1
1 2
1 1
2 1
2 2
3 1
3 4
;
run;
data need1(drop=temp);
set test(rename=(b=temp));
by a;
if first.a then do;
b=0;
end;
b+temp;
if last.a then output;
run;
proc means data=test noprint nway;
class a;
var b;
output out=need2(drop=_:) sum=;
run;