<?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: number of months that can be divisive by 12 in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/number-of-months-that-can-be-divisive-by-12/m-p/666992#M79044</link>
    <description>&lt;P&gt;Here you go.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  stock=2;
  do count=1 to 14;
    output;
  end;
  stock=1;
  do count=1 to 26;
    output;
  end;
  stop;
run;

proc sort data=have;
  by stock count;
run;

data max_count(keep=stock max_count);
  set have(keep=stock count);
  by stock count;
  if last.stock then
    do;
      max_count=count-mod(count,12);
      output;
    end;
run;

data want;
  merge have max_count; 
  by stock;
  if count&amp;gt;max_count then delete;
run;

proc print data=want;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1593923043775.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/46904i5621BD3D8DB3702B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1593923043775.png" alt="Patrick_0-1593923043775.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 05 Jul 2020 04:24:13 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2020-07-05T04:24:13Z</dc:date>
    <item>
      <title>number of months that can be divisive by 12</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/number-of-months-that-can-be-divisive-by-12/m-p/666969#M79039</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am fairly new to SAS and I have a project that I need to figure out how to find the number of months that can be divisive by 12. For example, if the stock has 76 months of data available, I need to round down to 72 months by removing the oldest 4 months of data. Any help would be greatly appreciated. Thanks.&lt;/P&gt;</description>
      <pubDate>Sun, 05 Jul 2020 02:11:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/number-of-months-that-can-be-divisive-by-12/m-p/666969#M79039</guid>
      <dc:creator>skyland1991</dc:creator>
      <dc:date>2020-07-05T02:11:47Z</dc:date>
    </item>
    <item>
      <title>Re: number of months that can be divisive by 12</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/number-of-months-that-can-be-divisive-by-12/m-p/666977#M79040</link>
      <description>&lt;P&gt;You could use the &lt;A href="https://go.documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=p0ebxby8k7049en12wrfx28vyx4t.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_self"&gt;mod()&lt;/A&gt; function for this.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  month_count=76;
  month12=month_count-mod(month_count,12);
  output;
  stop;
run;

proc print data=test;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1593917410783.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/46903i106A2D9CA5FFE394/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1593917410783.png" alt="Patrick_0-1593917410783.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 05 Jul 2020 02:50:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/number-of-months-that-can-be-divisive-by-12/m-p/666977#M79040</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-07-05T02:50:18Z</dc:date>
    </item>
    <item>
      <title>Re: number of months that can be divisive by 12</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/number-of-months-that-can-be-divisive-by-12/m-p/666988#M79041</link>
      <description>&lt;P&gt;Thank you Patrick. What if I have a consecutive number of months that look like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;count&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;2&lt;/P&gt;&lt;P&gt;3&lt;/P&gt;&lt;P&gt;4&lt;/P&gt;&lt;P&gt;5&lt;/P&gt;&lt;P&gt;6&lt;/P&gt;&lt;P&gt;7&lt;/P&gt;&lt;P&gt;8&lt;/P&gt;&lt;P&gt;9&lt;/P&gt;&lt;P&gt;10&lt;/P&gt;&lt;P&gt;11&lt;/P&gt;&lt;P&gt;12&lt;/P&gt;&lt;P&gt;13&lt;/P&gt;&lt;P&gt;14&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;how do I get rid of month 13 and 14? Thank you.&lt;/P&gt;</description>
      <pubDate>Sun, 05 Jul 2020 04:03:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/number-of-months-that-can-be-divisive-by-12/m-p/666988#M79041</guid>
      <dc:creator>skyland1991</dc:creator>
      <dc:date>2020-07-05T04:03:41Z</dc:date>
    </item>
    <item>
      <title>Re: number of months that can be divisive by 12</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/number-of-months-that-can-be-divisive-by-12/m-p/666989#M79042</link>
      <description>&lt;P&gt;You will first have to figure out the max count. Would you need to do this by stock or in total (meaning if for one stock you've got 24 months but for another only 14 months then you would want to select only 12 months for both stocks)?&lt;/P&gt;</description>
      <pubDate>Sun, 05 Jul 2020 04:11:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/number-of-months-that-can-be-divisive-by-12/m-p/666989#M79042</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-07-05T04:11:42Z</dc:date>
    </item>
    <item>
      <title>Re: number of months that can be divisive by 12</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/number-of-months-that-can-be-divisive-by-12/m-p/666990#M79043</link>
      <description>&lt;P&gt;Thank you for the reply. I need to do this by stock. for example if one stock has 14 I need 12, and another has 26 I need 24.&lt;/P&gt;</description>
      <pubDate>Sun, 05 Jul 2020 04:13:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/number-of-months-that-can-be-divisive-by-12/m-p/666990#M79043</guid>
      <dc:creator>skyland1991</dc:creator>
      <dc:date>2020-07-05T04:13:38Z</dc:date>
    </item>
    <item>
      <title>Re: number of months that can be divisive by 12</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/number-of-months-that-can-be-divisive-by-12/m-p/666992#M79044</link>
      <description>&lt;P&gt;Here you go.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  stock=2;
  do count=1 to 14;
    output;
  end;
  stock=1;
  do count=1 to 26;
    output;
  end;
  stop;
run;

proc sort data=have;
  by stock count;
run;

data max_count(keep=stock max_count);
  set have(keep=stock count);
  by stock count;
  if last.stock then
    do;
      max_count=count-mod(count,12);
      output;
    end;
run;

data want;
  merge have max_count; 
  by stock;
  if count&amp;gt;max_count then delete;
run;

proc print data=want;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1593923043775.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/46904i5621BD3D8DB3702B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1593923043775.png" alt="Patrick_0-1593923043775.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 05 Jul 2020 04:24:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/number-of-months-that-can-be-divisive-by-12/m-p/666992#M79044</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-07-05T04:24:13Z</dc:date>
    </item>
    <item>
      <title>Re: number of months that can be divisive by 12</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/number-of-months-that-can-be-divisive-by-12/m-p/666993#M79045</link>
      <description>&lt;P&gt;Or if you are more a SQL kind-of guy (or if your source data resides in a data base)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  create table want as
  select l.*
  from 
    have l
    inner join
    (
      select stock, max(count)-mod(max(count),12) as max_count
      from have
      group by stock
    ) r
    on l.stock=r.stock and l.count&amp;lt;=r.max_count
  order by l.stock, l.count
  ;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 05 Jul 2020 04:30:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/number-of-months-that-can-be-divisive-by-12/m-p/666993#M79045</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-07-05T04:30:31Z</dc:date>
    </item>
    <item>
      <title>Re: number of months that can be divisive by 12</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/number-of-months-that-can-be-divisive-by-12/m-p/666994#M79046</link>
      <description>&lt;P&gt;Thank you so much for all your answers! They really help a lot!&lt;/P&gt;</description>
      <pubDate>Sun, 05 Jul 2020 04:32:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/number-of-months-that-can-be-divisive-by-12/m-p/666994#M79046</guid>
      <dc:creator>skyland1991</dc:creator>
      <dc:date>2020-07-05T04:32:03Z</dc:date>
    </item>
    <item>
      <title>Re: number of months that can be divisive by 12</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/number-of-months-that-can-be-divisive-by-12/m-p/667304#M79070</link>
      <description>&lt;P&gt;Hi Patrick,&lt;/P&gt;&lt;P&gt;Sorry to bother you again. I have a follow-up question, suppose I have got the number of months that can be divisive by 12, how can I further calculate the average price for each successive 12-month period (eg, if I have 120 months of data, I would like to have 10 trailing 12-month average prices)? Thank you.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jul 2020 22:07:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/number-of-months-that-can-be-divisive-by-12/m-p/667304#M79070</guid>
      <dc:creator>skyland1991</dc:creator>
      <dc:date>2020-07-06T22:07:24Z</dc:date>
    </item>
  </channel>
</rss>

