hpu2009 发表于 2010-10-16 15:09 
算法如下:
Here is an example,
data tmp;
do t=1 to 10;
x=ranuni(123);
output;
end;
run;
data tmp2;
set tmp;
xlag=lag(x);
n+1;
if n>1 then do;
r=x>xlag;
s+r;
end;
run;
proc print;run;
****************************
Obs t x xlag n r s
1 1 0.75040 . 1 . 0
2 2 0.32091 0.75040 2 0 0
3 3 0.17839 0.32091 3 0 0
4 4 0.90603 0.17839 4 1 1
5 5 0.35712 0.90603 5 0 1
6 6 0.22111 0.35712 6 0 1
7 7 0.78644 0.22111 7 1 2
8 8 0.39808 0.78644 8 0 2
9 9 0.12467 0.39808 9 0 2
10 10 0.18769 0.12467 10 1 3