Follow the link for more details,
http://support.sas.com/documentation/cdl/en/statug/63962/HTML/default/viewer.htm#statug_mcmc_sect064.htm
options cmplib = (sasuser.funcs.temp);
proc fcmp outlib=sasuser.funcs.temp;;
/******************************************/
/* Generate left-truncated normal variate */
/******************************************/
function rltnorm(mu,sig,lwr);
if lwr<mu then do;
ans = lwr-1;
do while(ans<lwr);
ans = rand('normal',mu,sig);
end;
end;
else do;
mul = (lwr-mu)/sig;
alpha = (mul + sqrt(mul**2 + 4))/2;
accept=0;
do while(accept=0);
z = mul + rand('exponential')/alpha;
lrho = -(z-alpha)**2/2;
u = rand('uniform');
lu = log(u);
if lu <= lrho then accept=1;
end;
ans = sig*z + mu;
end;
return(ans);
endsub;
run;
data t1;
call streaminit(123);
do i=1 to 10000;
mu=0;sig=1;lwr=-1;
x=rltnorm(mu,sig,lwr);
output;
end;
run;
proc print data=t1(obs=10);run;
proc univariate data=t1;
var x;
histogram x/normal;
inset n mean std skewness kurtosis/pos=ne;
run;



雷达卡



京公网安备 11010802022788号







