<?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: cumulating the n previous rows depending the number of the month in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/cumulating-the-n-previous-rows-depending-the-number-of-the-month/m-p/408692#M99808</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
retain cum_amount 0;
cum_amount + amount;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Depending on where you want to start, you have to set a condition for the increment statement.&lt;/P&gt;</description>
    <pubDate>Mon, 30 Oct 2017 14:32:05 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2017-10-30T14:32:05Z</dc:date>
    <item>
      <title>cumulating the n previous rows depending the number of the month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/cumulating-the-n-previous-rows-depending-the-number-of-the-month/m-p/408689#M99805</link>
      <description>&lt;P&gt;hello,&lt;/P&gt;&lt;P&gt;This is the data set "have".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
informat year_month yymmn6.;
format year_month date9.;
input year_month monthNum amount ;
datalines;
201511 11 110
201512 12 112
201601 1 101
201602 2 102
201603 3 103
201604 4 104
201605 5 105
201606 6 106
201607 7 107
201608 8 108
201609 9 109
201610 10 110
201611 11 111
201612 12 112
201701 1 101
;
run ;&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;&lt;BR /&gt;And what I would like is to cumulate the amount like this&amp;nbsp; :&lt;BR /&gt;--&amp;gt; for month n° 1, cumulate the last 2 month&lt;BR /&gt;--&amp;gt; for month n° 2, cumulate the last 3 month&lt;BR /&gt;--&amp;gt; for month n° 3, cumulate the last 4 month&lt;BR /&gt;...&lt;BR /&gt;...&lt;BR /&gt;--&amp;gt; for month n° 12, cumulate the last 13 month&lt;/P&gt;</description>
      <pubDate>Mon, 30 Oct 2017 14:27:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/cumulating-the-n-previous-rows-depending-the-number-of-the-month/m-p/408689#M99805</guid>
      <dc:creator>Nasser_DRMCP</dc:creator>
      <dc:date>2017-10-30T14:27:03Z</dc:date>
    </item>
    <item>
      <title>Re: cumulating the n previous rows depending the number of the month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/cumulating-the-n-previous-rows-depending-the-number-of-the-month/m-p/408692#M99808</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
retain cum_amount 0;
cum_amount + amount;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Depending on where you want to start, you have to set a condition for the increment statement.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Oct 2017 14:32:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/cumulating-the-n-previous-rows-depending-the-number-of-the-month/m-p/408692#M99808</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-10-30T14:32:05Z</dc:date>
    </item>
    <item>
      <title>Re: cumulating the n previous rows depending the number of the month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/cumulating-the-n-previous-rows-depending-the-number-of-the-month/m-p/408696#M99809</link>
      <description>&lt;P&gt;Something like:&lt;/P&gt;
&lt;PRE&gt;data have;
  informat year_month yymmn6.;
  format year_month date9.;
  input year_month monthNum amount;
  yr=year(year_month);
datalines;
201511 11 110
201512 12 112
201601 1 101
201602 2 102
201603 3 103
201604 4 104
201605 5 105
201606 6 106
201607 7 107
201608 8 108
201609 9 109
201610 10 110
201611 11 111
201612 12 112
201701 1 101
;
run;
proc sort data=have;
  by yr monthnum;
run;
data want;
  set have;
  retain cumulate;
  by yr;
  cumulate=ifn(first.yr,amount,cumulate+amount);
run;

&lt;/PRE&gt;</description>
      <pubDate>Mon, 30 Oct 2017 14:35:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/cumulating-the-n-previous-rows-depending-the-number-of-the-month/m-p/408696#M99809</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-10-30T14:35:21Z</dc:date>
    </item>
    <item>
      <title>Re: cumulating the n previous rows depending the number of the month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/cumulating-the-n-previous-rows-depending-the-number-of-the-month/m-p/408721#M99814</link>
      <description>&lt;P&gt;Thanks a lot Kurt but I do not succeed to get the attended result.&lt;/P&gt;&lt;P&gt;example, for jan2016&amp;nbsp;, the cumul is all values having month &amp;lt;= jan2016 instead of jan+dec only.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Oct 2017 15:02:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/cumulating-the-n-previous-rows-depending-the-number-of-the-month/m-p/408721#M99814</guid>
      <dc:creator>Nasser_DRMCP</dc:creator>
      <dc:date>2017-10-30T15:02:39Z</dc:date>
    </item>
    <item>
      <title>Re: cumulating the n previous rows depending the number of the month</title>
      <link>https://communities.sas.com/t5/SAS-Programming/cumulating-the-n-previous-rows-depending-the-number-of-the-month/m-p/408731#M99816</link>
      <description>&lt;P&gt;You need to set a condition or a starting point, in your case a (re-)starting point:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
retain cum_amount 0;
cum_amount + amount;
output;
if month(year_month) = 12 then cum_amount = amount;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Oct 2017 15:10:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/cumulating-the-n-previous-rows-depending-the-number-of-the-month/m-p/408731#M99816</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-10-30T15:10:00Z</dc:date>
    </item>
  </channel>
</rss>

