下面的程序运行的超慢 ,各位高手能否帮我看看,是不是有可以改进的地方,在此多谢了。
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;
options cmplib=sasuser.funcs;
proc fcmp outlib=sasuser.funcs.math ;
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;run;
proc fcmp outlib=sasuser.funcs.statistics;
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;
proc printto log=_null_;
run;
options cmplib=sasuser.funcs;
%macro arim(r);
%do m=1 %to &r;
data data.lstar&m;
set ab;
do i=1 to 2000;
x=rand('T',3);
y=x/sqrt(3);
lstar=lstar(y,c,d);
l=g(y);
output;
end;
run;
data data.ci&m;
set data.lstar&m;
retain sum1 0;
sum1=sum1+lstar;
if (sum1 ge 0) then sum1=sum1;
else sum1=0;
output;keep i sum1;
run;
data data.si&m;
set data.lstar&m;
retain sum2 0;
sum2=sum2+l;
if (sum2 ge 0) then sum2=sum2;
else sum2=0;
output;keep i sum2;
run;
%end;
%mend arim;
%arim(10000);
proc printto log=_null_;
run;
libname data 'c:\SASDATA';
%macro ar(u);
%do n=1 %to &u;
%macro arim(r);
%do m=1 %to &r;
data shifts&m&n;
set data.ci&m;
if (sum1 ge (2.01+0.01*(&n-1))) then output;
run;
data shift&m&n;
set shifts&m&n;
if _n_=1 then output;keep i;
run;
data drifts&m&n;
set data.si&m;
if (sum2 ge (2.01+0.01*(&n-1))) then output;
run;
data drift&m&n;
set drifts&m&n;
if _n_=1 then output;keep i;
run;
%end;
%mend arim;
%arim(10000);
%macro test;
data sumshift&n;
set %do m=1 %to 10000;
shift&m&n
%end;
;
data sumdrift&n;
set %do m=1 %to 10000;
drift&m&n
%end;
;
%mend test;
%test;
%end;
%mend ar;
%ar(10);
%macro ar(u);
%do n=1 %to &u;
proc means data=sumshift&n;
var i;
output out=ci_shift&n(drop =_freq_ _type_)mean=ARL;
run;
proc means data=sumdrift&n;
var i;
output out=si_drift&n(drop =_freq_ _type_)mean=sARL;
run;
%end;
%mend ar;
%ar(10);
data ci_mean;
set ci_shift1-ci_shift10;
run;
data si_mean;
set si_drift1-si_drift10;
run;
data h;
do h=2.01 to 3 by 0.01;
output;end;
run;
libname SASDATA 'c:\SASDATA1';
data SASDATA.RLCUSUM6;
merge ci_mean si_mean h;
run;
proc gplot data=SASDATA.RLCUSUM6;
plot ARL*h=1 sARL*h=2/overlay;
symbol1 i=none v=dot;
symbol2 i=none v=dot c=black;
run;
proc gplot data=SASDATA.RLCUSUM6;
plot ARL*h=1 sARL*h=2;
symbol1 i=join v=none;
symbol2 i=join v=none;
run;
proc gplot data=SASDATA.RLCUSUM6;
plot ARL*h=1 sARL*h=2/overlay;
symbol1 i=join v=none;
symbol2 i=join v=none;
run;