<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Using Computer simulation to look for convergence in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-Computer-simulation-to-look-for-convergence/m-p/406971#M279129</link>
    <description>&lt;P&gt;I think it is helpful to concentrate on one problem at a time. See if you can understand this modification of your program, which addresses only the first problem ("E(M)").&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Let M = min {n: X1 + X2 + ... + Xn&amp;gt; 1}. Find E(M)=expected value of M */
data new ;
do i=1 to 10000;
   sum=0 ;
   M=0 ;
   do until (sum&amp;gt;1) ;
      u = rand('uniform');
      sum+u;
      M+1 ;
   end ;
   output;
end;
run;
 
proc means data=new;
var M;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you understand this problem, do something similar for the second problem. I don't think you need an array. Hint:&amp;nbsp;the DO UNTIL loop might look something like DO UNTIL(u &amp;lt; prevU).&amp;nbsp; Somewhere in the program you will need to set prevU=u.&lt;/P&gt;
&lt;P&gt;PrevU&amp;nbsp;= u&lt;/P&gt;</description>
    <pubDate>Tue, 24 Oct 2017 15:07:32 GMT</pubDate>
    <dc:creator>Rick_SAS</dc:creator>
    <dc:date>2017-10-24T15:07:32Z</dc:date>
    <item>
      <title>Using Computer simulation to look for convergence</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Computer-simulation-to-look-for-convergence/m-p/405269#M279124</link>
      <description>&lt;P&gt;Suppose X&lt;SPAN style="font-size: 11.6667px;"&gt;i&lt;/SPAN&gt;&amp;nbsp;for i=1, 2, 3… has uniform (0, 1) distribution.&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Let M = min (n: X1 + X2 + … + Xn&amp;gt; 1). Find expected value of&amp;nbsp; M; E(M).&lt;/LI&gt;&lt;LI&gt;Let N = min (n: Xn &amp;gt; Xn+1). Find expected value of&amp;nbsp; N; E (N).&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;A one unit stick is broken randomly into two pieces.&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Find E (the short piece divided by the long piece).&lt;/LI&gt;&lt;LI&gt;Find E (the long piece divided by the short piece).&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am completely confused on how to start this simulation. Some clarity and direction would be great. Thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 18 Oct 2017 16:19:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Computer-simulation-to-look-for-convergence/m-p/405269#M279124</guid>
      <dc:creator>jsjoden</dc:creator>
      <dc:date>2017-10-18T16:19:07Z</dc:date>
    </item>
    <item>
      <title>Re: Using Computer simulation to look for convergence</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Computer-simulation-to-look-for-convergence/m-p/405302#M279125</link>
      <description>&lt;P&gt;Try first to answer these basic questions (in plain language):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is E(&lt;EM&gt;something&lt;/EM&gt;)?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How do you estimate E(&lt;EM&gt;something&lt;/EM&gt;) by simulation?&lt;/P&gt;</description>
      <pubDate>Wed, 18 Oct 2017 18:05:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Computer-simulation-to-look-for-convergence/m-p/405302#M279125</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2017-10-18T18:05:38Z</dc:date>
    </item>
    <item>
      <title>Re: Using Computer simulation to look for convergence</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Computer-simulation-to-look-for-convergence/m-p/405368#M279126</link>
      <description>&lt;P&gt;Maybe this will give you a start on the second.&lt;/P&gt;
&lt;PRE&gt;data start;
   do i= 1 to 100;
      r= rand('uniform');
      Short = min(r,1-r);
      long  = max(r,1-r);
      output;
   end;
run;&lt;/PRE&gt;
&lt;P&gt;You can obviously add variables for the ratios between the long and short pieces.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The r variable above will have a sample of uniform(0,1) values.&lt;/P&gt;
&lt;P&gt;If&lt;/P&gt;</description>
      <pubDate>Wed, 18 Oct 2017 21:43:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Computer-simulation-to-look-for-convergence/m-p/405368#M279126</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-10-18T21:43:48Z</dc:date>
    </item>
    <item>
      <title>Re: Using Computer simulation to look for convergence</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Computer-simulation-to-look-for-convergence/m-p/405607#M279127</link>
      <description>&lt;P&gt;You might want to read the article (especially the comments) &lt;A href="https://blogs.sas.com/content/iml/2012/09/26/expected-number-of-uniform-numbers.html" target="_self"&gt;"The expected number of uniform variates whose sum exceeds one."&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For the broken stick problem, see the article &lt;A href="https://blogs.sas.com/content/iml/2017/07/26/random-segments-broken-sticks.html" target="_self"&gt;"Random segments and broken sticks"&lt;/A&gt;. The last paragraph gives some hints about how to simulate the problem in the DATA step.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Oct 2017 15:30:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Computer-simulation-to-look-for-convergence/m-p/405607#M279127</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2017-10-19T15:30:26Z</dc:date>
    </item>
    <item>
      <title>Re: Using Computer simulation to look for convergence</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Computer-simulation-to-look-for-convergence/m-p/406757#M279128</link>
      <description>&lt;P&gt;Hi Rick,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for pointing me in the right direction. The first link that you provided is very similar to as what I am trying to do. However, I am new to SAS and have not gotten to proc iml yet. So loop would be more sufficient for me at this point. The code I got below seems to fit that. However, I am confused on some of the code. What does the first two lines do. retain and array? Then I am trying to print the E(N)/E(M) . As well after I am trying to find if there is a convergence or divergence.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;data new ;&lt;BR /&gt;retain sum count mean _2 - _12 ;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;BR /&gt;array counts[*] _2 - _12 ;&lt;BR /&gt;do i=1 to 500 ;&lt;BR /&gt;sum=0 ;&lt;BR /&gt;count=0 ;&lt;BR /&gt;do until (sum&amp;gt;1) ;&lt;BR /&gt;sum+rand('uniform') ;&lt;BR /&gt;count+1 ;&lt;BR /&gt;end ;&lt;BR /&gt;mean+count ;&lt;BR /&gt;do j=2 to dim(counts) ;&lt;BR /&gt;if j=count then counts[j-1]+1 ;&lt;BR /&gt;end ;&lt;BR /&gt;end ;&lt;BR /&gt;mean=mean/i ;&lt;BR /&gt;output ;&lt;BR /&gt;run ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc freq data= doh;&lt;BR /&gt;table sum / plots=FreqPlot(scale=percent) nocum;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Oct 2017 22:42:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Computer-simulation-to-look-for-convergence/m-p/406757#M279128</guid>
      <dc:creator>jsjoden</dc:creator>
      <dc:date>2017-10-23T22:42:53Z</dc:date>
    </item>
    <item>
      <title>Re: Using Computer simulation to look for convergence</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Computer-simulation-to-look-for-convergence/m-p/406971#M279129</link>
      <description>&lt;P&gt;I think it is helpful to concentrate on one problem at a time. See if you can understand this modification of your program, which addresses only the first problem ("E(M)").&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Let M = min {n: X1 + X2 + ... + Xn&amp;gt; 1}. Find E(M)=expected value of M */
data new ;
do i=1 to 10000;
   sum=0 ;
   M=0 ;
   do until (sum&amp;gt;1) ;
      u = rand('uniform');
      sum+u;
      M+1 ;
   end ;
   output;
end;
run;
 
proc means data=new;
var M;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you understand this problem, do something similar for the second problem. I don't think you need an array. Hint:&amp;nbsp;the DO UNTIL loop might look something like DO UNTIL(u &amp;lt; prevU).&amp;nbsp; Somewhere in the program you will need to set prevU=u.&lt;/P&gt;
&lt;P&gt;PrevU&amp;nbsp;= u&lt;/P&gt;</description>
      <pubDate>Tue, 24 Oct 2017 15:07:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Computer-simulation-to-look-for-convergence/m-p/406971#M279129</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2017-10-24T15:07:32Z</dc:date>
    </item>
    <item>
      <title>Re: Using Computer simulation to look for convergence</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Computer-simulation-to-look-for-convergence/m-p/407100#M279130</link>
      <description>&lt;P&gt;I got it. So I came up with this. However, It is stuck in running the data step, so I am always having to cancel the submitted statement. Can you take a look if I did something wrong. Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data dt1 ;&lt;BR /&gt;do i=1 to 10000;&lt;BR /&gt;sum = 0;&lt;BR /&gt;M=0 ;&lt;BR /&gt;u = rand('uniform');&lt;BR /&gt;prevU = u;&lt;BR /&gt;do until (u&amp;lt;prevU) ;&lt;BR /&gt;sum+u;&lt;BR /&gt;M+1 ;&lt;BR /&gt;end ;&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc means data=dt1;&lt;BR /&gt;var M;&lt;BR /&gt;title'hope';&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Oct 2017 22:36:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Computer-simulation-to-look-for-convergence/m-p/407100#M279130</guid>
      <dc:creator>jsjoden</dc:creator>
      <dc:date>2017-10-24T22:36:36Z</dc:date>
    </item>
    <item>
      <title>Re: Using Computer simulation to look for convergence</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Computer-simulation-to-look-for-convergence/m-p/407175#M279131</link>
      <description>&lt;P&gt;I assume this is for #2 (expected value of N). You are close. You need to update the values of prevU&amp;nbsp;INSIDE the loop or else the loop will never end.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dt1;
do i=1 to 10000;
   N=1;                    /* want 1 here instead of 0 */
   u = rand('uniform');
   prevU = u;
   do until (prevU &amp;gt; u) ;
      prevU = u;          /* remember last u */
      u = rand('uniform');/* generate new u */
      N+1 ;
   end;
   output;
end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 25 Oct 2017 09:35:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Computer-simulation-to-look-for-convergence/m-p/407175#M279131</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2017-10-25T09:35:56Z</dc:date>
    </item>
    <item>
      <title>Re: Using Computer simulation to look for convergence</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Computer-simulation-to-look-for-convergence/m-p/510003#M279132</link>
      <description>&lt;P&gt;Just wondering, how would we know if it converges or diverges? If it does converge how do we find the value?&lt;/P&gt;</description>
      <pubDate>Fri, 02 Nov 2018 18:22:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Computer-simulation-to-look-for-convergence/m-p/510003#M279132</guid>
      <dc:creator>JamesHawthorne</dc:creator>
      <dc:date>2018-11-02T18:22:32Z</dc:date>
    </item>
    <item>
      <title>Re: Using Computer simulation to look for convergence</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Computer-simulation-to-look-for-convergence/m-p/601187#M279133</link>
      <description>&lt;P&gt;But how would you know if it converges?&lt;/P&gt;</description>
      <pubDate>Sat, 02 Nov 2019 23:20:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Computer-simulation-to-look-for-convergence/m-p/601187#M279133</guid>
      <dc:creator>valarievil</dc:creator>
      <dc:date>2019-11-02T23:20:37Z</dc:date>
    </item>
  </channel>
</rss>

