标题: 请教有关SAS产生随机数的问题 [打印本页] 作者: shiyiming 时间: 2008-3-17 21:45 标题: 请教有关SAS产生随机数的问题 第一次用SAS这个软件,由于时间紧迫,临时突击,迷糊!
请教大家,
随机变量a的取值如果有十个(a1,a2,a3,...)
随机变量b 的取值也有十个(b1,b2,b3,...)
如何利用sas,将a,b的取值任意组合,一千次,得Y=a^2+b^3的分布啊?
万分感谢 <!-- s:D --><img src="{SMILIES_PATH}/icon_biggrin.gif" alt=":D" title="Very Happy" /><!-- s:D -->作者: shiyiming 时间: 2008-3-22 02:37 标题: Re: 请教有关SAS产生随机数的问题 This approach is nasty but it gets the job done. I have a hard time to find other ways to do it, someone else here could have a better idea. Hope this helps and good luck.
/* Get all combinations between a and b */
proc iml;
a={1 2 3 4 5 6 7 8 9 10 };
b={11 12 13 14 15 16 17 18 19 20};
allcomb = j(100,2,1);
do i=1 to 10;
ai=a[1,i];
do j=1 to 10;
aj=b[1,j];
allcomb[10*(i-1)+j,1]=ai;
allcomb[10*(i-1)+j,2]=aj;
end;
end;
create comb from allcomb[colname={'a' 'b'}];
append from allcomb;
quit;
/* Randomly sample the combinaion 1000 times with replacement */
proc surveyselect data=comb method = urs sampsize = 1000
rep=1 seed=12345 out=sampling;
id a b;
run;
/* Output the completed dataset */
data allsamples;
set sampling;
do i = 1 to numberhits;
output;
end;
drop i numberhits;
run;
/* calculate Y */
data yvalue;
set allsamples;
Y = a**2 + b**3 ;
run;
ods html;
ods graphics on;
proc univariate data=yvalue plot;
var y;
run;
ods graphics off;
ods html close;作者: shiyiming 时间: 2008-4-1 14:26 标题: Re: 请教有关SAS产生随机数的问题 谢谢hotea, 你的帖子给了我很大的帮助,真的很感谢!作者: shiyiming 时间: 2008-4-2 03:42 标题: to belleyang You are quite welcome!!