SAS中文论坛

标题: 请教应用sas如何进行蒙特卡罗模拟 [打印本页]

作者: shiyiming    时间: 2004-3-19 15:23
标题: 请教应用sas如何进行蒙特卡罗模拟
我要求获得4个变量,1000组不相关、独立的服从N(0,1)分布的数据集,请问用sas如何实现?
作者: shiyiming    时间: 2004-3-19 23:50
标题: Re: 请教应用sas如何进行蒙特卡罗模拟
[quote="gbt":a99aa]我要求获得4个变量,1000组不相关、独立的服从N(0,1)分布的数据集,请问用sas如何实现?[/quote:a99aa]

[code:a99aa]data a;
do i=1 to 1000;
  x1=rannor(1);
  x2=rannor(2);
  x3=rannor(3);
  x4=rannor(4);
  output;
end;
run;[/code:a99aa]

Please be noted that you are talking about independence between x_i and x_j, not records.
作者: shiyiming    时间: 2004-3-20 10:24
生成的是随机数字吗?为什么每次运行的结果都是一样?
作者: shiyiming    时间: 2004-3-20 12:48
it's pseudo-random numbers, fixed when the seed is fixed except you use 0 as the seed.
作者: shiyiming    时间: 2004-3-22 02:06
Sorry, it should be written as

[code:d786f]data a;
do i=1 to 1000;
  x1=rannor(0);
  x2=rannor(0);
  x3=rannor(0);
  x4=rannor(0);
  output;
end;
run;[/code:d786f]

in case you do not want to see the repeated measure.
作者: shiyiming    时间: 2004-3-23 19:12
rannor(0)
参数为0时,随机数种子为系统时间,所以每次不一样,如果你不为0,每次当然是
同一组随机数了(随机数种子相同)




欢迎光临 SAS中文论坛 (http://mysas.net/forum/) Powered by Discuz! X3.2