<?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: Compute quantity in a recursive way in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Compute-quantity-in-a-recursive-way/m-p/240187#M268345</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If this is what you want then you do not need Lag()&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop=v12sum);
set have;
by id;
retain v12sum;
if first.id then v12sum=v1;
else do ;
v12sum=v12sum+v2;
v1=v12sum;
end; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 20 Dec 2015 23:55:33 GMT</pubDate>
    <dc:creator>mohamed_zaki</dc:creator>
    <dc:date>2015-12-20T23:55:33Z</dc:date>
    <item>
      <title>Compute quantity in a recursive way</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compute-quantity-in-a-recursive-way/m-p/240183#M268342</link>
      <description>&lt;P&gt;Dear All,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I have the following dataset:&lt;/SPAN&gt;&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;PRE&gt;data have;
&amp;nbsp;&amp;nbsp; input id&amp;nbsp;V1 V2;
datalines;
1  10&amp;nbsp; &amp;nbsp;3
1 &amp;nbsp; . &amp;nbsp;&amp;nbsp;4
1 &amp;nbsp; .   5
2 &amp;nbsp;20&amp;nbsp; &amp;nbsp;5
2 &amp;nbsp;&amp;nbsp;. &amp;nbsp; 7
2 &amp;nbsp; . &amp;nbsp; 8;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to obtain the following dataset want. That is, I want&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;V1 = lag(V1)+V2&amp;nbsp;for&amp;nbsp;those observations such that first.id is not true (starting from the second one of each id group)&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;PRE&gt;&lt;CODE class=" language-sas"&gt;data&amp;nbsp;want;
&amp;nbsp;&amp;nbsp; input id&amp;nbsp;V1 V2;
datalines;
1  10 &amp;nbsp;&amp;nbsp;3
1  14  &amp;nbsp;4
1  19 &amp;nbsp; 5
2 &amp;nbsp;20&amp;nbsp; &amp;nbsp;5
2 &amp;nbsp;27 &amp;nbsp; 7
2 &amp;nbsp;35 &amp;nbsp; 8;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help would e highly appreciated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 20 Dec 2015 23:35:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compute-quantity-in-a-recursive-way/m-p/240183#M268342</guid>
      <dc:creator>mark_ph</dc:creator>
      <dc:date>2015-12-20T23:35:05Z</dc:date>
    </item>
    <item>
      <title>Re: Compute quantity in a recursive way</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compute-quantity-in-a-recursive-way/m-p/240185#M268343</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop=lag_v1) ;
set have;
by id;
lag_v1=lag(V1);
if first.id then V3=V1;
else V3=lag_v1+4;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I &amp;nbsp;think you have mistaken the value of&amp;nbsp;V3 in the last row&amp;nbsp;in your data want&lt;/P&gt;</description>
      <pubDate>Sun, 20 Dec 2015 23:34:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compute-quantity-in-a-recursive-way/m-p/240185#M268343</guid>
      <dc:creator>mohamed_zaki</dc:creator>
      <dc:date>2015-12-20T23:34:50Z</dc:date>
    </item>
    <item>
      <title>Re: Compute quantity in a recursive way</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compute-quantity-in-a-recursive-way/m-p/240186#M268344</link>
      <description>Dear &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/49185"&gt;@mohamed_zaki&lt;/a&gt;, I'm really sorry. I did a mistake including V3 in my previous toy example. I have just updated it.</description>
      <pubDate>Sun, 20 Dec 2015 23:37:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compute-quantity-in-a-recursive-way/m-p/240186#M268344</guid>
      <dc:creator>mark_ph</dc:creator>
      <dc:date>2015-12-20T23:37:06Z</dc:date>
    </item>
    <item>
      <title>Re: Compute quantity in a recursive way</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compute-quantity-in-a-recursive-way/m-p/240187#M268345</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If this is what you want then you do not need Lag()&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop=v12sum);
set have;
by id;
retain v12sum;
if first.id then v12sum=v1;
else do ;
v12sum=v12sum+v2;
v1=v12sum;
end; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 20 Dec 2015 23:55:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compute-quantity-in-a-recursive-way/m-p/240187#M268345</guid>
      <dc:creator>mohamed_zaki</dc:creator>
      <dc:date>2015-12-20T23:55:33Z</dc:date>
    </item>
    <item>
      <title>Re: Compute quantity in a recursive way</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compute-quantity-in-a-recursive-way/m-p/240205#M268346</link>
      <description>&lt;P&gt;Though the solution is already provided, here is an alternative approach.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope you &lt;STRONG&gt;like&lt;/STRONG&gt; it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have(rename=v1=_v1);
retain v1;
by id;
if first.id then v1=_v1;
else v1=sum(v1,v2);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Dec 2015 03:39:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compute-quantity-in-a-recursive-way/m-p/240205#M268346</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2015-12-21T03:39:09Z</dc:date>
    </item>
  </channel>
</rss>

