<?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: Nested Do Loop (Only want to accumulate within 1 loop) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Nested-Do-Loop-Only-want-to-accumulate-within-1-loop/m-p/159721#M31109</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks a lot to both of you for your help.&amp;nbsp; Both solutions worked perfectly. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 30 Jun 2014 12:24:34 GMT</pubDate>
    <dc:creator>Statistics91</dc:creator>
    <dc:date>2014-06-30T12:24:34Z</dc:date>
    <item>
      <title>Nested Do Loop (Only want to accumulate within 1 loop)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Nested-Do-Loop-Only-want-to-accumulate-within-1-loop/m-p/159718#M31106</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I currently have this program which is supposed to simulate a gambling strategy (educational purposes; this is not a winning strategy by any means).&amp;nbsp; My program is not quite working because when the 2nd iteration of k begins, the InHand variable continues to accumulate from the final value of when k = 1.&amp;nbsp; Essentially, I need the InHand to go back to starting at 0 when a new iteration of k begins.&amp;nbsp; Basically, I just want to repeat everything in the 'i' loop 10,000 times&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Does anyone have an idea of a modification I can make to fix this?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data gamble;&lt;/P&gt;&lt;P&gt;do k = 1 to 10000;&lt;/P&gt;&lt;P&gt;do i = 1 to 100000 until (Strategy = "STOP");&lt;/P&gt;&lt;P&gt;Win = RAND('BINOMIAL',0.476,1);&lt;/P&gt;&lt;P&gt;if Win = 1 then Payoff = 5;&lt;/P&gt;&lt;P&gt;else if Win = 0 then Payoff = -5;&lt;/P&gt;&lt;P&gt;InHand + Payoff;&lt;/P&gt;&lt;P&gt;if InHand &amp;gt;= 45 then Strategy = "STOP";&lt;/P&gt;&lt;P&gt;else if InHand &amp;lt;= -50 then Strategy = "STOP";&lt;/P&gt;&lt;P&gt;else Strategy = "CONTINUE";&lt;/P&gt;&lt;P&gt;if InHand = 45 then Result = "WIN ";&lt;/P&gt;&lt;P&gt;else Result = "LOSS";&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;output;&lt;/P&gt;&lt;P&gt;output;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you in advance!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 29 Jun 2014 04:21:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Nested-Do-Loop-Only-want-to-accumulate-within-1-loop/m-p/159718#M31106</guid>
      <dc:creator>Statistics91</dc:creator>
      <dc:date>2014-06-29T04:21:53Z</dc:date>
    </item>
    <item>
      <title>Re: Nested Do Loop (Only want to accumulate within 1 loop)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Nested-Do-Loop-Only-want-to-accumulate-within-1-loop/m-p/159719#M31107</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This is what you need?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data gamble;&lt;/P&gt;&lt;P&gt;do k = 1 to 10000;&lt;/P&gt;&lt;P&gt;do i = 1 to 100000 until (Strategy = "STOP");&lt;/P&gt;&lt;P&gt;Win = RAND('BINOMIAL',0.476,1);&lt;/P&gt;&lt;P&gt;if Win = 1 then Payoff = 5;&lt;/P&gt;&lt;P&gt;else if Win = 0 then Payoff = -5;&lt;/P&gt;&lt;P&gt;InHand + Payoff;&lt;/P&gt;&lt;P&gt;if InHand &amp;gt;=45 or inHand&amp;lt;=-50 then Strategy = "STOP";&lt;/P&gt;&lt;P&gt;else Strategy = "CONTINUE";&lt;/P&gt;&lt;P&gt;if InHand = 45 then Result = "WIN ";&lt;/P&gt;&lt;P&gt;else Result = "LOSS";&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;output;&lt;/P&gt;&lt;P&gt;call missing(Inhand);&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 29 Jun 2014 15:43:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Nested-Do-Loop-Only-want-to-accumulate-within-1-loop/m-p/159719#M31107</guid>
      <dc:creator>slchen</dc:creator>
      <dc:date>2014-06-29T15:43:46Z</dc:date>
    </item>
    <item>
      <title>Re: Nested Do Loop (Only want to accumulate within 1 loop)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Nested-Do-Loop-Only-want-to-accumulate-within-1-loop/m-p/159720#M31108</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;All you need is the statement &lt;STRONG&gt;InHand = 0;&lt;/STRONG&gt; after &lt;STRONG&gt;do k = 1 to 10000;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;I also suggest calling STREAMINIT as the first statement of the datastep to get reproducible results.&amp;nbsp; &lt;/P&gt;&lt;P&gt;Why two output statements?&lt;/P&gt;&lt;P&gt;You may also consider replacing the BINOMIAL distribution with the BERNOULLI.&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 29 Jun 2014 15:53:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Nested-Do-Loop-Only-want-to-accumulate-within-1-loop/m-p/159720#M31108</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2014-06-29T15:53:08Z</dc:date>
    </item>
    <item>
      <title>Re: Nested Do Loop (Only want to accumulate within 1 loop)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Nested-Do-Loop-Only-want-to-accumulate-within-1-loop/m-p/159721#M31109</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks a lot to both of you for your help.&amp;nbsp; Both solutions worked perfectly. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Jun 2014 12:24:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Nested-Do-Loop-Only-want-to-accumulate-within-1-loop/m-p/159721#M31109</guid>
      <dc:creator>Statistics91</dc:creator>
      <dc:date>2014-06-30T12:24:34Z</dc:date>
    </item>
  </channel>
</rss>

