试试这个
data db1;
do until(last.ID);
set DB;
by ID;
if first.ID then Total = 0;
Total + sum(of Value:);
end;
do until(last.ID);
set DB;
by ID;
if not first.ID then Total = .;
output;
end;
run;
结果:
ID Value1 Value2 Value3 Total
0001 33 . . 61
0001 . 22 . .
0001 . . . .
0001 . . 6 .
0002 . 32 . 36
0002 . . 4 .
0003 . 2 90 95
0003 3 . . .