pobel 发表于 2013-4-4 16:16 
楼主把代码贴出来会更容易判断。
libname DATA 'c:\SASDATA';
data DATA.ab;
a=-0.618;
b=1.618;
v=1+a*a;
u=1+(1-a)**2;
t=1+b*b;
s=1+(b-1)**2;
la=2*log(v/u);
lb=2*log(t/s);
c=la/log(1+a*a);
d=lb/log(1+b*b);
keep c d;
run;
proc fcmp outlib=sasuser.funcs.math_stat;
function lstar(u,c,d);
if (u le -0.618) then return (c*log(1+u*u));
if (u ge 1.618) then return (d*log(1+u*u));
else return(2*log((1+u*u)/(1+(u-1)*(u-1))));
endsub;
function g(u);
if (u le -0.25) then return (2*log((1+0.25*0.25)/(1+1.25*1.25)));
if (u ge 1.25) then return (2*log((1+1.25*1.25)/(1+0.25*0.25)));
else return(2*log((1+u*u)/(1+(u-1)*(u-1))));
endsub;
run;
options cmplib =sasuser.funcs;
%let r =10000;
data lstar;
call streaminit(1234);
set data.ab;
do sample =1 to &r;
call missing(sum1, sum2);
do i =1 to 2000;
x =rand('T',3) ;
y =x/sqrt(3) ;
lstar =lstar(y,c,d) ;
l =g(y) ;
sum1 ++lstar; sum2 ++l;
if (sum1 lt 0) then sum1=0;
if (sum2 lt 0) then sum2=0;
output;
end;
end;
keep sample i sum1 sum2;
run;
data shifts_drifts;
set lstar;
by sample;
array _n[10] _temporary_ (1 2 3 4 5 6 7 8 9 10);
array _s[10] _temporary_; array _d[10] _temporary_;
if first.sample then call missing(of _s
_d);
do k =1 to dim(_n);
if _s[k] <1 then if (sum1 ge (2.01+0.01*(_n[k]-1))) then do;
_s[k] =1; n =_n[k]; cat ='shifts';
output shifts_drifts;
keep sample n i cat;
end;
if _d[k] <1 then if (sum2 ge (2.01+0.01*(_n[k]-1))) then do;
_d[k] =1; n =_n[k]; cat ='drifts';
output shifts_drifts;
keep sample n i cat;
end;
end;
run;
proc means data=shifts_drifts;
class n cat;
var i;
output out=ci_shifts_drifts(drop =_freq_ _type_) mean=ARL_sARL;
run;
data h;
do h=2 to 2.09 by 0.01;
output;end;run;
data c;
set ci_shifts_drifts;
if n=. then delete;
if cat='shifts' then output;
label ARL_sARL='ARL';drop n cat;
run;
data s;
set ci_shifts_drifts;
if n=. then delete;
if cat='drifts' then output;
label ARL_sARL='sARL';drop n cat;
run;
data l;
merge c s h ;run;
proc gplot data=last;
plot ARL*h=1 sARL*h=2/overlay;
symbol1 i=join v=none;
symbol2 i=join v=none;
run;