<?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 Cumulative sum in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Cumulative-sum/m-p/323439#M271193</link>
    <description>&lt;P&gt;I am trying to find cumulative sum by year for different makers.&lt;/P&gt;&lt;P&gt;here is my dataset&lt;/P&gt;&lt;P&gt;DATA CUMLILATIVE;&lt;BR /&gt;INPUT maker $ MON YEAR sale sale1;&lt;BR /&gt;DATALINES;&lt;BR /&gt;maruti 1 2015 12 13&lt;BR /&gt;maruti 2 2016 13 23&lt;BR /&gt;maruti 6 2015 17 18&lt;BR /&gt;honda 2 2015 8 9&lt;BR /&gt;honda 1 2015 16 19&lt;BR /&gt;tata 1 2015 16 19&lt;BR /&gt;tata 2 2015 16 19&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Output will be like&lt;/P&gt;&lt;P&gt;Maruti 1 2015 12 13&lt;/P&gt;&lt;P&gt;maruti 6 2015 29 31&lt;/P&gt;&lt;P&gt;maruti &amp;nbsp;2 2016 13 23&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;honda 1 2015 16 19&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;honda 2 2015 24 &amp;nbsp;28&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;and so on&lt;/P&gt;&lt;P&gt;As for maruti we have different year (i.e. 2015 and 2016) the cumulative sum must be year wise.&lt;/P&gt;&lt;P&gt;Please help&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;</description>
    <pubDate>Mon, 09 Jan 2017 19:01:31 GMT</pubDate>
    <dc:creator>Nitish1003</dc:creator>
    <dc:date>2017-01-09T19:01:31Z</dc:date>
    <item>
      <title>Cumulative sum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cumulative-sum/m-p/323439#M271193</link>
      <description>&lt;P&gt;I am trying to find cumulative sum by year for different makers.&lt;/P&gt;&lt;P&gt;here is my dataset&lt;/P&gt;&lt;P&gt;DATA CUMLILATIVE;&lt;BR /&gt;INPUT maker $ MON YEAR sale sale1;&lt;BR /&gt;DATALINES;&lt;BR /&gt;maruti 1 2015 12 13&lt;BR /&gt;maruti 2 2016 13 23&lt;BR /&gt;maruti 6 2015 17 18&lt;BR /&gt;honda 2 2015 8 9&lt;BR /&gt;honda 1 2015 16 19&lt;BR /&gt;tata 1 2015 16 19&lt;BR /&gt;tata 2 2015 16 19&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Output will be like&lt;/P&gt;&lt;P&gt;Maruti 1 2015 12 13&lt;/P&gt;&lt;P&gt;maruti 6 2015 29 31&lt;/P&gt;&lt;P&gt;maruti &amp;nbsp;2 2016 13 23&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;honda 1 2015 16 19&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;honda 2 2015 24 &amp;nbsp;28&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;and so on&lt;/P&gt;&lt;P&gt;As for maruti we have different year (i.e. 2015 and 2016) the cumulative sum must be year wise.&lt;/P&gt;&lt;P&gt;Please help&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;</description>
      <pubDate>Mon, 09 Jan 2017 19:01:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cumulative-sum/m-p/323439#M271193</guid>
      <dc:creator>Nitish1003</dc:creator>
      <dc:date>2017-01-09T19:01:31Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative sum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cumulative-sum/m-p/323446#M271194</link>
      <description>&lt;P&gt;First sort your data:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=have;&lt;/P&gt;
&lt;P&gt;by maker year mon;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that MAKER must take on the same spelling.&amp;nbsp; "Maruti" is different than "maruti".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then accumulate:&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;by maker year;&lt;/P&gt;
&lt;P&gt;if first.year then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; tot_sales = sale;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; tot_sales1 = sale1;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;else do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; tot_sales + sale;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; tot_sales1 + sale1;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;drop sale sale1;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Jan 2017 19:18:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cumulative-sum/m-p/323446#M271194</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-01-09T19:18:59Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative sum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cumulative-sum/m-p/323472#M271195</link>
      <description>&lt;P&gt;Same but slightly more compact:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WANT;
  set HAVE;
  by MAKER YEAR;
  if first.YEAR then call missing(TOT_SALES,TOT_SALES1);
  TOT_SALES  + SALE;
  TOT_SALES1 + SALE1;
  drop SALE SALE1;
run;&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Jan 2017 22:51:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cumulative-sum/m-p/323472#M271195</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2017-01-09T22:51:31Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative sum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cumulative-sum/m-p/323534#M271196</link>
      <description>&lt;P&gt;Thanks for the help both code are working properly.&lt;/P&gt;&lt;P&gt;need one more help can you please guide me how can i get same output through proc sqll&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jan 2017 06:27:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cumulative-sum/m-p/323534#M271196</guid>
      <dc:creator>Nitish1003</dc:creator>
      <dc:date>2017-01-10T06:27:09Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative sum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cumulative-sum/m-p/323545#M271197</link>
      <description>&lt;P&gt;My SQL is relatively weak, so this falls into the category of "worth a try":&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;/P&gt;
&lt;P&gt;create table want as&amp;nbsp;&lt;/P&gt;
&lt;P&gt;select a.maker, a.year, a.mon. sum(b.sales) as totsales, sum(b.sales1) as totsales1&lt;/P&gt;
&lt;P&gt;from have a, have b&lt;/P&gt;
&lt;P&gt;where (b.year &amp;lt; a.year) or (b.year = a.year and b.mon &amp;lt;= a.mon)&lt;/P&gt;
&lt;P&gt;group by a.maker, a.year, a.mon;&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In general, SQL does not guarantee an order to the observations. &amp;nbsp;So problems that depend on the order become more difficult.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jan 2017 08:06:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cumulative-sum/m-p/323545#M271197</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-01-10T08:06:52Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative sum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cumulative-sum/m-p/323548#M271198</link>
      <description>&lt;P&gt;Actually &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;got very close.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;proc sql;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;create table want as &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;select a.maker, a.year, a.mon, sum(b.sale) as sales, sum(b.sale1) as&amp;nbsp;sales1&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;from have a, have b&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;where a.maker = b.maker and b.year = a.year and b.mon &amp;lt;= a.mon&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;group by a.maker, a.year, a.mon;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;quit;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;&lt;SPAN&gt;Hope it helps.&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;&lt;SPAN&gt;Daniel Santos&amp;nbsp;@ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jan 2017 08:21:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cumulative-sum/m-p/323548#M271198</guid>
      <dc:creator>Daniel-Santos</dc:creator>
      <dc:date>2017-01-10T08:21:25Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative sum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cumulative-sum/m-p/323763#M271199</link>
      <description>&lt;P&gt;Thanks for the help.Query is working fine&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jan 2017 20:34:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cumulative-sum/m-p/323763#M271199</guid>
      <dc:creator>Nitish1003</dc:creator>
      <dc:date>2017-01-10T20:34:29Z</dc:date>
    </item>
  </channel>
</rss>

