<?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: Rolling 12 months, calculating frequence in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Rolling-12-months-calculating-frequence/m-p/231916#M54626</link>
    <description>&lt;P&gt;Using an array:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
     input jaar maand claims ptf;
     cards;
     2014 01 575 250555
     2014 02 555 251555
     2014 03 501 252256
     2014 04 556 252222
     2014 05 587 253000
     2014 06 595 253599
     2014 07 459 254568
     2014 08 531 254998
    2014 09 598 255998
    2014 10 358 256687
     2014 11 589 257169
     2014 12 456 258859
     2015 01 598 259589
     2015 02 433 264210
;

%let nbMonths=4;

data want;
array sc(0:&amp;amp;nbMonths) _temporary_;
array sp(0:&amp;amp;nbMonths) _temporary_;
set have;
sc{mod(_n_, &amp;amp;nbMonths)} = claims;
sp{mod(_n_, &amp;amp;nbMonths)} = ptf;
if n(of sc{*}) = &amp;amp;nbMonths and n(of sp{*}) = &amp;amp;nbMonths then&lt;BR /&gt; claimRate = sum(of sc{*}) / sum(of sp{*});
run;

proc print data=want noobs; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 27 Oct 2015 22:04:43 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2015-10-27T22:04:43Z</dc:date>
    <item>
      <title>Rolling 12 months, calculating frequence</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Rolling-12-months-calculating-frequence/m-p/231913#M54625</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm looking for an easy way to calculate an avarage frequency of reported claims for the last 4 (to keep it easy) months.&amp;nbsp;So for every observation (month) I will have to create a new variable that is the ratio between de sum of the claims of the last 4 months, over the sum of contracts in 'portefeuille' of the last 4 months.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; out;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; input jaar maand claims portefeuille;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cards;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2014 01 575 250555&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2014 02 555 251555&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2014 03 501 252256&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2014 04 556 252222&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2014 05 587 253000&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2014 06 595 253599&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2014 07 459 254568&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2014 08 531 254998&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2014 09 598 255998&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2014 10 358 256687&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2014 11 589 257169&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2014 12 456 258859&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2015 01 598 259589&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2015 02 433 264210&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is what I do;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data out1;&lt;/P&gt;&lt;P&gt;set out;&lt;/P&gt;&lt;P&gt;cl1=lag(claims);&lt;/P&gt;&lt;P&gt;cl2=lag2(claims);&lt;/P&gt;&lt;P&gt;cl3=lag3(claims);&lt;/P&gt;&lt;P&gt;ptf1=lag(ptf);&lt;/P&gt;&lt;P&gt;ptf1=lag1(ptf);&lt;/P&gt;&lt;P&gt;ptf3=lag2(ptf);&lt;/P&gt;&lt;P&gt;freq=(claims+cl1+cl2+cl3)/(ptf+ptf1+ptf2+ptf3);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For this data set and 4 months, this works fine. But when I want to do this for more months, variables , ... this procedure is quite extencive. Is there an other way? I have been looking for a 'Do While' and 'Array', but I don't find anything that works for me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;&lt;P&gt;Leonard&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;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Oct 2015 21:08:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Rolling-12-months-calculating-frequence/m-p/231913#M54625</guid>
      <dc:creator>Leonard32</dc:creator>
      <dc:date>2015-10-27T21:08:46Z</dc:date>
    </item>
    <item>
      <title>Re: Rolling 12 months, calculating frequence</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Rolling-12-months-calculating-frequence/m-p/231916#M54626</link>
      <description>&lt;P&gt;Using an array:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
     input jaar maand claims ptf;
     cards;
     2014 01 575 250555
     2014 02 555 251555
     2014 03 501 252256
     2014 04 556 252222
     2014 05 587 253000
     2014 06 595 253599
     2014 07 459 254568
     2014 08 531 254998
    2014 09 598 255998
    2014 10 358 256687
     2014 11 589 257169
     2014 12 456 258859
     2015 01 598 259589
     2015 02 433 264210
;

%let nbMonths=4;

data want;
array sc(0:&amp;amp;nbMonths) _temporary_;
array sp(0:&amp;amp;nbMonths) _temporary_;
set have;
sc{mod(_n_, &amp;amp;nbMonths)} = claims;
sp{mod(_n_, &amp;amp;nbMonths)} = ptf;
if n(of sc{*}) = &amp;amp;nbMonths and n(of sp{*}) = &amp;amp;nbMonths then&lt;BR /&gt; claimRate = sum(of sc{*}) / sum(of sp{*});
run;

proc print data=want noobs; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Oct 2015 22:04:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Rolling-12-months-calculating-frequence/m-p/231916#M54626</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2015-10-27T22:04:43Z</dc:date>
    </item>
    <item>
      <title>Re: Rolling 12 months, calculating frequence</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Rolling-12-months-calculating-frequence/m-p/231919#M54628</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is another way with PROC SQL....&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data in;
     input y:4. m:2. claims:3. ptf:8.;
     cards;
     2014 01 575 250555
     2014 02 555 251555
     2014 03 501 252256
     2014 04 556 252222
     2014 05 587 253000
     2014 06 595 253599
     2014 07 459 254568
     2014 08 531 254998
    2014 09 598 255998
    2014 10 358 256687
     2014 11 589 257169
     2014 12 456 258859
     2015 01 598 259589
     2015 02 433 264210
     ;
run;
data in; set in; c1=lag1(claims);c2=lag2(claims);c3=lag3(claims);
                 p1=lag1(ptf); p2=lag2(ptf); p3=lag3(ptf);
proc sql;
select y,m,claims,ptf,(( claims+c1+c2+c3)/(ptf+p1+p2+p3)) as myratio
  from in;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Good Luck...!!!&lt;/P&gt;</description>
      <pubDate>Tue, 27 Oct 2015 21:46:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Rolling-12-months-calculating-frequence/m-p/231919#M54628</guid>
      <dc:creator>kannand</dc:creator>
      <dc:date>2015-10-27T21:46:25Z</dc:date>
    </item>
    <item>
      <title>Re: Rolling 12 months, calculating frequence</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Rolling-12-months-calculating-frequence/m-p/231925#M54632</link>
      <description>&lt;P&gt;With SQL, I would prefer:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc sql;
create table wantSQL as
select a.*, sum(b.claims)/sum(b.ptf) as claimRate
from have as a inner join have as b
on intck("MONTH", mdy(a.maand,1,a.jaar), mdy(b.maand,1,b.jaar)) 
    between -3 and 0
group by a.jaar, a.maand, a.claims, a.ptf;
select * from wantSQL;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 27 Oct 2015 22:19:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Rolling-12-months-calculating-frequence/m-p/231925#M54632</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2015-10-27T22:19:09Z</dc:date>
    </item>
    <item>
      <title>Re: Rolling 12 months, calculating frequence</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Rolling-12-months-calculating-frequence/m-p/231927#M54634</link>
      <description>&lt;P&gt;PG - I seem to learn something new from you almost every day... Thx for the technical contribution....&lt;/P&gt;</description>
      <pubDate>Tue, 27 Oct 2015 22:21:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Rolling-12-months-calculating-frequence/m-p/231927#M54634</guid>
      <dc:creator>kannand</dc:creator>
      <dc:date>2015-10-27T22:21:17Z</dc:date>
    </item>
    <item>
      <title>Re: Rolling 12 months, calculating frequence</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Rolling-12-months-calculating-frequence/m-p/231929#M54636</link>
      <description>&lt;P&gt;Here's a DATA step approach that is amenable to adding more variables and a variety of numbers of months:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;totclaims + claims;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;totclaims_L4 + lag4(claims);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;totptf + ptf;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;totptf_L4 + lag4(ptf);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;freq4 = (totclaims - totclaims_L4) / (totptf - totptf_L4);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if you need 8-month calculations as well, just compute totclaims_L8 + lag8(claims)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good luck.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Oct 2015 22:44:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Rolling-12-months-calculating-frequence/m-p/231929#M54636</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2015-10-27T22:44:59Z</dc:date>
    </item>
  </channel>
</rss>

