<?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: Cumulative Sum for the current row and the 12 next rows in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Cumulative-Sum-for-the-current-row-and-the-12-next-rows/m-p/549956#M152665</link>
    <description>&lt;P&gt;hello&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;whenever there are less than 12 month ,&amp;nbsp;no need so I would like get null&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;</description>
    <pubDate>Wed, 10 Apr 2019 13:50:04 GMT</pubDate>
    <dc:creator>Nasser_DRMCP</dc:creator>
    <dc:date>2019-04-10T13:50:04Z</dc:date>
    <item>
      <title>Cumulative Sum for the current row and the 12 next rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cumulative-Sum-for-the-current-row-and-the-12-next-rows/m-p/549947#M152661</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have ; 
  input product $1. month amount ;
datalines; 
A 1601 1
A 1602 2
A 1603 3
A 1604 4
A 1605 5
A 1606 6
A 1607 7
A 1608 8
A 1609 9
A 1610 10
A 1611 11
A 1612 12
A 1701 13
A 1702 14
A 1703 15
A 1704 16
A 1705 17
A 1706 18
A 1707 19
A 1708 20
A 1709 21
A 1710 22
A 1711 23
A 1712 24
B 1601 1
B 1602 2
B 1603 3
B 1604 4
B 1605 5
B 1606 6
B 1607 7
B 1608 8
B 1609 90
B 1610 100
B 1611 110
B 1612 120
B 1701 130
B 1702 140
B 1703 150
B 1704 160
B 1705 170
B 1706 180
B 1707 190
B 1708 200
B 1709 210
B 1710 220
B 1711 230
B 1712 240
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;this is my input dataset.&lt;/P&gt;&lt;P&gt;I try to get a column that woulb be the cumulative sum of the current row and the next 12.&lt;BR /&gt;And that for each product.&lt;/P&gt;&lt;P&gt;for example , for product A and month 201609 , the result should be 195 because that is the sum of 9,10,11.....20,21&lt;BR /&gt;for example , for product B and month 201609 , the result should be 2170 because that is the sum of 90,100....210,220&lt;BR /&gt;thanks in advance for your help&lt;/P&gt;&lt;P&gt;regards,&lt;/P&gt;&lt;P&gt;Nasser&lt;/P&gt;</description>
      <pubDate>Wed, 10 Apr 2019 13:36:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cumulative-Sum-for-the-current-row-and-the-12-next-rows/m-p/549947#M152661</guid>
      <dc:creator>Nasser_DRMCP</dc:creator>
      <dc:date>2019-04-10T13:36:47Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative Sum for the current row and the 12 next rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cumulative-Sum-for-the-current-row-and-the-12-next-rows/m-p/549955#M152664</link>
      <description>What would you like the results to be for&lt;BR /&gt;&lt;BR /&gt;B 1710 220&lt;BR /&gt;&lt;BR /&gt;when you only have a few more months of data?</description>
      <pubDate>Wed, 10 Apr 2019 13:46:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cumulative-Sum-for-the-current-row-and-the-12-next-rows/m-p/549955#M152664</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-04-10T13:46:32Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative Sum for the current row and the 12 next rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cumulative-Sum-for-the-current-row-and-the-12-next-rows/m-p/549956#M152665</link>
      <description>&lt;P&gt;hello&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;whenever there are less than 12 month ,&amp;nbsp;no need so I would like get null&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;</description>
      <pubDate>Wed, 10 Apr 2019 13:50:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cumulative-Sum-for-the-current-row-and-the-12-next-rows/m-p/549956#M152665</guid>
      <dc:creator>Nasser_DRMCP</dc:creator>
      <dc:date>2019-04-10T13:50:04Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative Sum for the current row and the 12 next rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cumulative-Sum-for-the-current-row-and-the-12-next-rows/m-p/549957#M152666</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ; 
  input product $1. month : yymmn4. amount ;
  format month yymmn6.;
datalines; 
A 1601 1
A 1602 2
A 1603 3
A 1604 4
A 1605 5
A 1606 6
A 1607 7
A 1608 8
A 1609 9
A 1610 10
A 1611 11
A 1612 12
A 1701 13
A 1702 14
A 1703 15
A 1704 16
A 1705 17
A 1706 18
A 1707 19
A 1708 20
A 1709 21
A 1710 22
A 1711 23
A 1712 24
B 1601 1
B 1602 2
B 1603 3
B 1604 4
B 1605 5
B 1606 6
B 1607 7
B 1608 8
B 1609 90
B 1610 100
B 1611 110
B 1612 120
B 1701 130
B 1702 140
B 1703 150
B 1704 160
B 1705 170
B 1706 180
B 1707 190
B 1708 200
B 1709 210
B 1710 220
B 1711 230
B 1712 240
;
run;

proc sql;
create table want as
select *,(select sum(amount) from have where product=a.product and
month between a.month and intnx('month',a.month,12)) as want
 from have as a;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 10 Apr 2019 13:51:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cumulative-Sum-for-the-current-row-and-the-12-next-rows/m-p/549957#M152666</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-04-10T13:51:02Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative Sum for the current row and the 12 next rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cumulative-Sum-for-the-current-row-and-the-12-next-rows/m-p/549969#M152670</link>
      <description>&lt;P&gt;&lt;BR /&gt;Hello Ksharp&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;sorry but it does not seem to work.maybe my need was not clear enough.&lt;/P&gt;&lt;P&gt;in the output table want, the resut for product A and 1609 month is 264 but 195 is atended coming from&amp;nbsp; sum of 9+10+11+12+13+14+15+16+17+18+19+20+21&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Apr 2019 14:14:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cumulative-Sum-for-the-current-row-and-the-12-next-rows/m-p/549969#M152670</guid>
      <dc:creator>Nasser_DRMCP</dc:creator>
      <dc:date>2019-04-10T14:14:51Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative Sum for the current row and the 12 next rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cumulative-Sum-for-the-current-row-and-the-12-next-rows/m-p/549972#M152671</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;





data have ; 
  input product $1. month amount ;
datalines; 
A 1601 1
A 1602 2
A 1603 3
A 1604 4
A 1605 5
A 1606 6
A 1607 7
A 1608 8
A 1609 9
A 1610 10
A 1611 11
A 1612 12
A 1701 13
A 1702 14
A 1703 15
A 1704 16
A 1705 17
A 1706 18
A 1707 19
A 1708 20
A 1709 21
A 1710 22
A 1711 23
A 1712 24
B 1601 1
B 1602 2
B 1603 3
B 1604 4
B 1605 5
B 1606 6
B 1607 7
B 1608 8
B 1609 90
B 1610 100
B 1611 110
B 1612 120
B 1701 130
B 1702 140
B 1703 150
B 1704 160
B 1705 170
B 1706 180
B 1707 190
B 1708 200
B 1709 210
B 1710 220
B 1711 230
B 1712 240
;
run;

data want;
if _n_=1 then do;
if 0 then set have;
  dcl hash H (dataset:'have',ordered: "A") ;
   h.definekey  ("product","month") ;
   h.definedata ("amount") ;
   h.definedone () ;
   dcl hiter ih('h');
end;
set have(drop=amount);
by product month;
RC = IH.SETCUR() ;
_p=product;
do count = 1 to 13 while (RC = 0 and _p=product) ;
sum=sum(sum,amount);
  RC = IH.next() ;
 end ;
if count &amp;lt; 13 then sum=0;
drop rc count product;
rename _p=product;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 10 Apr 2019 14:23:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cumulative-Sum-for-the-current-row-and-the-12-next-rows/m-p/549972#M152671</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-04-10T14:23:31Z</dc:date>
    </item>
  </channel>
</rss>

