<?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 How can I loop a value of a variable created in each iteration of a DO loop? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-loop-a-value-of-a-variable-created-in-each-iteration/m-p/85092#M256935</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am a beginner SAS user.&amp;nbsp; In this simulation, there is an initial value of the variable called "p", but there will be a new value (called "newp" in code below") calculated by SAS for each iteration in the simulation.&amp;nbsp; How can I get this value that is created in each iteration to be used in the iteration that follows?&amp;nbsp; See code below.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That is, when gen=1, the value of "p" is 0.00005.&amp;nbsp; Based on the results of the simulation a "newp" will be calculated using the entered formula.&amp;nbsp; This "newp" should be used for gen=2, where again, another different "newp" is calculated and should be used in gen=3, and so forth.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data a;&lt;/P&gt;&lt;P&gt;do gen=1 to 10;&lt;/P&gt;&lt;P&gt;seed=47639087;&lt;/P&gt;&lt;P&gt;expon=2*ranuni(seed) + 4;&lt;/P&gt;&lt;P&gt;n=round(10**expon,1);&lt;/P&gt;&lt;P&gt;p=.00005;&lt;/P&gt;&lt;P&gt;q=1-p;&lt;/P&gt;&lt;P&gt;NumRR = round(n*p*p,1); &lt;/P&gt;&lt;P&gt;NumSR = round(2*n*p*q,1); &lt;/P&gt;&lt;P&gt;NumSS = round(n*q*q,1); &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;newp=(NumRR + .5*NumSR) / (Numrr + numsr&amp;nbsp; + numss);&lt;/P&gt;&lt;P&gt;diffp=p-newp;&lt;/P&gt;&lt;P&gt;newq=(NumSS + .5*NumSR)/ (Numrr + numsr&amp;nbsp; + numss);&lt;/P&gt;&lt;P&gt;diffq=q-newq;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;output; &lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 17 Sep 2013 18:05:51 GMT</pubDate>
    <dc:creator>cu139</dc:creator>
    <dc:date>2013-09-17T18:05:51Z</dc:date>
    <item>
      <title>How can I loop a value of a variable created in each iteration of a DO loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-loop-a-value-of-a-variable-created-in-each-iteration/m-p/85092#M256935</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am a beginner SAS user.&amp;nbsp; In this simulation, there is an initial value of the variable called "p", but there will be a new value (called "newp" in code below") calculated by SAS for each iteration in the simulation.&amp;nbsp; How can I get this value that is created in each iteration to be used in the iteration that follows?&amp;nbsp; See code below.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That is, when gen=1, the value of "p" is 0.00005.&amp;nbsp; Based on the results of the simulation a "newp" will be calculated using the entered formula.&amp;nbsp; This "newp" should be used for gen=2, where again, another different "newp" is calculated and should be used in gen=3, and so forth.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data a;&lt;/P&gt;&lt;P&gt;do gen=1 to 10;&lt;/P&gt;&lt;P&gt;seed=47639087;&lt;/P&gt;&lt;P&gt;expon=2*ranuni(seed) + 4;&lt;/P&gt;&lt;P&gt;n=round(10**expon,1);&lt;/P&gt;&lt;P&gt;p=.00005;&lt;/P&gt;&lt;P&gt;q=1-p;&lt;/P&gt;&lt;P&gt;NumRR = round(n*p*p,1); &lt;/P&gt;&lt;P&gt;NumSR = round(2*n*p*q,1); &lt;/P&gt;&lt;P&gt;NumSS = round(n*q*q,1); &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;newp=(NumRR + .5*NumSR) / (Numrr + numsr&amp;nbsp; + numss);&lt;/P&gt;&lt;P&gt;diffp=p-newp;&lt;/P&gt;&lt;P&gt;newq=(NumSS + .5*NumSR)/ (Numrr + numsr&amp;nbsp; + numss);&lt;/P&gt;&lt;P&gt;diffq=q-newq;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;output; &lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Sep 2013 18:05:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-loop-a-value-of-a-variable-created-in-each-iteration/m-p/85092#M256935</guid>
      <dc:creator>cu139</dc:creator>
      <dc:date>2013-09-17T18:05:51Z</dc:date>
    </item>
    <item>
      <title>Re: How can I loop a value of a variable created in each iteration of a DO loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-loop-a-value-of-a-variable-created-in-each-iteration/m-p/85093#M256936</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;data a;&lt;/P&gt;&lt;P&gt;newp=.00005;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;do gen=1 to 10;&lt;/P&gt;&lt;P&gt;seed=47639087;&lt;/P&gt;&lt;P&gt;expon=2*ranuni(seed) + 4;&lt;/P&gt;&lt;P&gt;n=round(10**expon,1);&lt;/P&gt;&lt;P&gt;p=.newp;&lt;/P&gt;&lt;P&gt;q=1-p;&lt;/P&gt;&lt;P&gt;NumRR = round(n*p*p,1); &lt;/P&gt;&lt;P&gt;NumSR = round(2*n*p*q,1); &lt;/P&gt;&lt;P&gt;NumSS = round(n*q*q,1); &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;newp=(NumRR + .5*NumSR) / (Numrr + numsr&amp;nbsp; + numss);&lt;/P&gt;&lt;P&gt;diffp=p-newp;&lt;/P&gt;&lt;P&gt;newq=(NumSS + .5*NumSR)/ (Numrr + numsr&amp;nbsp; + numss);&lt;/P&gt;&lt;P&gt;diffq=q-newq;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;output; &lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Sep 2013 18:45:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-loop-a-value-of-a-variable-created-in-each-iteration/m-p/85093#M256936</guid>
      <dc:creator>DBailey</dc:creator>
      <dc:date>2013-09-17T18:45:14Z</dc:date>
    </item>
  </channel>
</rss>

