[code:fpfycogs]
data raw;
input val id;
datalines;
24 1
31 1
10 2
11 2
22 3
9 3
;
data ads;
set raw;
by id;
if first.id then subtot=0;
subtot+val;
output;
if last.id then do;
val=subtot;
id=.;
output;
end;
drop subtot;
run;
[/code:fpfycogs]