oloolo 发表于 2011-10-28 18:46 
data a;
input a;
cards;
SQL will be a clumsy approach for solving this problem. There is no observation order concept in database or SQL language. For example, find the third largest value of a variable.
The proposed solution would be wrong in following data ordering,
data a;
input a;
cards;
1
6
3
4
;
run;
data b;
set a;
b+a;
run;
proc print;run;
proc sql;
select a.a, sum(b.a) as b
from a as a, a as b
where a.a>=b.a
group by a.a
;
quit;