SAS中文论坛

标题: Random Number Seeds: NOT only the first one matters! [打印本页]

作者: shiyiming    时间: 2012-1-31 00:51
标题: Random Number Seeds: NOT only the first one matters!
From oloolo's blog on SasProgramming


<p><a href="http://feedads.g.doubleclick.net/~a/hGi5ZqD3K76tsjuRfn4ZY3p_7-g/0/da"><img src="http://feedads.g.doubleclick.net/~a/hGi5ZqD3K76tsjuRfn4ZY3p_7-g/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/hGi5ZqD3K76tsjuRfn4ZY3p_7-g/1/da"><img src="http://feedads.g.doubleclick.net/~a/hGi5ZqD3K76tsjuRfn4ZY3p_7-g/1/di" border="0" ismap="true"></img></a></p>Today, Rick (blog @ <a href="http://blogs.sas.com/content/iml/" target="_blank">here</a>) wrote an&nbsp;<a href="http://blogs.sas.com/content/iml/2012/01/30/random-number-seeds-only-the-first-seed-matters/?utm_source=feedburner&amp;utm_medium=feed&amp;utm_campaign=Feed%3A+TheDoLoop+%28The+DO+Loop%29" target="_blank">article</a> about random number seed in SAS to be used in random number functions in DATA Step. Rick noticed when multiple random number functions are called using different seeds, only the first one matters. <br />
<br />
This is so true. In fact, SAS Manual also has a comprehensive writting on this issue,&nbsp;namely, how to control seeds for each iteration of the random number generation process and how to generatie multiple statistically independent streams of random numbers, see <a href="http://support.sas.com/documentation/cdl/en/lefunctionsref/63354/HTML/default/viewer.htm#p026ygl6toz3tgn14lt4iu6cl5bb.htm#p04slf135yfs1sn1vrvrvso072d3" target="_blank">here</a>. In fact, sasCommunity.org also has an article about this issue, see <a href="http://www.sascommunity.org/wiki/How_the_SAS_Random_Number_Generators_Work" target="_blank">here</a>.<br />
<br />
To&nbsp;echo Rick's post,&nbsp; there is a way to control the seed so that NOT only the first one matters: use CALL routines which by theory will generate computationally independent random number sequence. But if the two seeds are too close, the generated sequences may not be statistically independent. Again, refer to the SAS manual for details.<br />
<br />
<br />
<pre style="background-color: #ebebeb; border-bottom: #999999 1px dashed; border-left: #999999 1px dashed; border-right: #999999 1px dashed; border-top: #999999 1px dashed; color: #000001; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding-bottom: 5px; padding-left: 5px; padding-right: 5px; padding-top: 5px; width: 100%;"><code>

data normal;
   seed1 = 11111;
   seed2 = 22222;
   seed3 = 383333;
   do i = 1 to 1000;
      call rannor(seed1, x1);
      call rannor(seed2, x2);   
      call rannor(seed3, x3);
   x4=rannor(seed2);
   x5=rannor(seed3);
      output;
   end;
run;

proc sgscatter data=normal;
   matrix x1-x5/ markerattrs = (size = 1);
run;

</code></pre><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/29815492-5189434209973827446?l=www.sas-programming.com' alt='' /></div><img src="http://feeds.feedburner.com/~r/SasProgramming/~4/E2VhkyIM6Rk" height="1" width="1"/>




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