data test1(drop= b i);
set test;
b=int(a);
do i= b to 0 by -1;
c1= a-i;
c2= (a-i)**2;
c3=(a-i)**3;
output;
end;
run;
data test2(keep= a sum1 sum2 sum3);
set test1;
retain sum1 sum2 sum3;
a1=lag(a);
if a ne a1 then
do;
sum1= c1;
sum2= c2;
sum3= c3;
end;
else if a = a1 then
do;
sum1= sum(sum1,c1);
sum2= sum(sum2,c2);
sum3= sum(sum3,c3);
end;
if a ne c1 then delete;
run;[/code:13739]