<?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: How to calculate cumulative sum using Lag function? in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-to-calculate-cumulative-sum-using-Lag-function/m-p/538932#M7003</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  cumulative_marks+marks;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You don't need anything more complicated.&lt;/P&gt;</description>
    <pubDate>Wed, 27 Feb 2019 11:48:12 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2019-02-27T11:48:12Z</dc:date>
    <item>
      <title>How to calculate cumulative sum using Lag function?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-calculate-cumulative-sum-using-Lag-function/m-p/538908#M6997</link>
      <description>&lt;P&gt;How to calculate cumulative sum of below data using Lag function?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Name Marks&lt;/P&gt;&lt;P&gt;AA&amp;nbsp; 50&lt;/P&gt;&lt;P&gt;BB 60&lt;/P&gt;&lt;P&gt;CC&amp;nbsp; 70&lt;/P&gt;&lt;P&gt;DD 80&lt;/P&gt;&lt;P&gt;EE 90&lt;/P&gt;&lt;P&gt;FF 100&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;output should be:&lt;/P&gt;&lt;P&gt;Name Marks&amp;nbsp; Cumulative marks&lt;/P&gt;&lt;P&gt;AA&amp;nbsp; &amp;nbsp; 50&amp;nbsp; &amp;nbsp;50&lt;/P&gt;&lt;P&gt;BB&amp;nbsp; &amp;nbsp;60&amp;nbsp; &amp;nbsp;110&lt;/P&gt;&lt;P&gt;CC&amp;nbsp; &amp;nbsp;70&amp;nbsp; 180&lt;/P&gt;&lt;P&gt;DD&amp;nbsp; 80&amp;nbsp; &amp;nbsp;260&lt;/P&gt;&lt;P&gt;EE&amp;nbsp; 90&amp;nbsp; 350&lt;/P&gt;&lt;P&gt;FF&amp;nbsp; 100 450&lt;/P&gt;</description>
      <pubDate>Wed, 27 Feb 2019 09:22:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-calculate-cumulative-sum-using-Lag-function/m-p/538908#M6997</guid>
      <dc:creator>aman23</dc:creator>
      <dc:date>2019-02-27T09:22:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate cumulative sum using Lag function?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-calculate-cumulative-sum-using-Lag-function/m-p/538909#M6998</link>
      <description>&lt;P&gt;Use retain, its what it is for:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  retain cumulative_marks;
  cumulative_marks=ifn(_n_=1,marks,sum(sumulative_marks,marks));
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 27 Feb 2019 09:23:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-calculate-cumulative-sum-using-Lag-function/m-p/538909#M6998</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2019-02-27T09:23:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate cumulative sum using Lag function?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-calculate-cumulative-sum-using-Lag-function/m-p/538910#M6999</link>
      <description>yes using retain can get the result, but can it be done using Lag function???</description>
      <pubDate>Wed, 27 Feb 2019 09:27:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-calculate-cumulative-sum-using-Lag-function/m-p/538910#M6999</guid>
      <dc:creator>aman23</dc:creator>
      <dc:date>2019-02-27T09:27:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate cumulative sum using Lag function?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-calculate-cumulative-sum-using-Lag-function/m-p/538912#M7001</link>
      <description>&lt;P&gt;Like any problem, it can be done, but why on earth would you want to go through that?&amp;nbsp; You would need to create a lag statement specifically for each row of data as you cannot conditionally execute lag statements, so this would not work:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  calc_marks=lag(calc_marks)+marks;
run;&lt;/PRE&gt;
&lt;P&gt;If you try it you will get all kinds of weird results as the value used in the lag (which is a queue of values) does not work conditionally.&lt;/P&gt;
&lt;P&gt;Use retain, its what its for.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Feb 2019 09:36:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-calculate-cumulative-sum-using-Lag-function/m-p/538912#M7001</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2019-02-27T09:36:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate cumulative sum using Lag function?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-calculate-cumulative-sum-using-Lag-function/m-p/538932#M7003</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  cumulative_marks+marks;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You don't need anything more complicated.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Feb 2019 11:48:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-calculate-cumulative-sum-using-Lag-function/m-p/538932#M7003</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-02-27T11:48:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate cumulative sum using Lag function?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-calculate-cumulative-sum-using-Lag-function/m-p/538985#M7011</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/258480"&gt;@aman23&lt;/a&gt;&amp;nbsp; did this&lt;/P&gt;
&lt;PRE&gt;  calc_marks=lag(calc_marks)+marks;&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;
&lt;P&gt;really work for your sample?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Feb 2019 14:38:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-calculate-cumulative-sum-using-Lag-function/m-p/538985#M7011</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-02-27T14:38:20Z</dc:date>
    </item>
  </channel>
</rss>

