<?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: do loop, retain and lag? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/do-loop-retain-and-lag/m-p/302072#M64005</link>
    <description>This also works great! Thank you both for responding so quickly.</description>
    <pubDate>Mon, 03 Oct 2016 14:40:17 GMT</pubDate>
    <dc:creator>sophia_SAS</dc:creator>
    <dc:date>2016-10-03T14:40:17Z</dc:date>
    <item>
      <title>do loop, retain and lag?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-loop-retain-and-lag/m-p/302057#M64001</link>
      <description>&lt;P&gt;Dear SAS community,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a very simple calculation problem that I can't quite seem to solve using a combination of do loops, lag functions and a retain statement. &amp;nbsp;In general, I would like to calculate a new denominator based on values from a previous numerator observation. &amp;nbsp; &amp;nbsp;For example on Day 2 - the denom = 499 because on Day 1 denom of 500 - numer of 1 = 499. &amp;nbsp;For day 3, the denom =&amp;nbsp;497 because the day 2 denom of&amp;nbsp;499 - day 2 numer of 2 = 497.&amp;nbsp;Below is what I would like my final dataset to look like. Thoughts?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;input day numer denom;&lt;/P&gt;&lt;P&gt;datalines;;&lt;/P&gt;&lt;P&gt;1 1 500&lt;/P&gt;&lt;P&gt;2 2 499&lt;/P&gt;&lt;P&gt;3 1 497&lt;/P&gt;&lt;P&gt;4 1 496&lt;/P&gt;&lt;P&gt;5 2 495&lt;/P&gt;&lt;P&gt;;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Oct 2016 14:19:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-loop-retain-and-lag/m-p/302057#M64001</guid>
      <dc:creator>sophia_SAS</dc:creator>
      <dc:date>2016-10-03T14:19:01Z</dc:date>
    </item>
    <item>
      <title>Re: do loop, retain and lag?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-loop-retain-and-lag/m-p/302062#M64002</link>
      <description>&lt;P&gt;It's not clear what you start with.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps this will help.&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;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Retain denom2;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Y = lag(numer);&lt;/P&gt;
&lt;P&gt;if _n_ ne 1 then denom2= denom2 - y;&lt;/P&gt;
&lt;P&gt;Else denom2=denom;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Oct 2016 14:29:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-loop-retain-and-lag/m-p/302062#M64002</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-10-03T14:29:43Z</dc:date>
    </item>
    <item>
      <title>Re: do loop, retain and lag?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-loop-retain-and-lag/m-p/302070#M64003</link>
      <description>&lt;P&gt;I would look at it in this way:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;new_denom = 500 - total_numer;&lt;/P&gt;
&lt;P&gt;total_numer + numer;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Adjustments could be made if you don't want to start at 500 each time.&amp;nbsp; But the subtraction has to take place first, before recalculating the TOTAL_NUMER.&lt;/P&gt;</description>
      <pubDate>Mon, 03 Oct 2016 14:38:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-loop-retain-and-lag/m-p/302070#M64003</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-10-03T14:38:04Z</dc:date>
    </item>
    <item>
      <title>Re: do loop, retain and lag?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-loop-retain-and-lag/m-p/302071#M64004</link>
      <description>This is great! Thank you so much!</description>
      <pubDate>Mon, 03 Oct 2016 14:38:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-loop-retain-and-lag/m-p/302071#M64004</guid>
      <dc:creator>sophia_SAS</dc:creator>
      <dc:date>2016-10-03T14:38:22Z</dc:date>
    </item>
    <item>
      <title>Re: do loop, retain and lag?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-loop-retain-and-lag/m-p/302072#M64005</link>
      <description>This also works great! Thank you both for responding so quickly.</description>
      <pubDate>Mon, 03 Oct 2016 14:40:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-loop-retain-and-lag/m-p/302072#M64005</guid>
      <dc:creator>sophia_SAS</dc:creator>
      <dc:date>2016-10-03T14:40:17Z</dc:date>
    </item>
  </channel>
</rss>

