<?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: How to change Months into Quarters in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-change-Months-into-Quarters/m-p/395741#M95491</link>
    <description>&lt;P&gt;hi linmuxi&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this case uou&amp;nbsp;could use the QTR function by translating the month to a date by using the MDY funtion with constants as values for day and year. Any year and any day (less than 29) will give the same result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;230 data _null_;&lt;BR /&gt;231 do months = 1 to 12;&lt;BR /&gt;232 quarters = qtr(mdy(months,1,2017));&lt;BR /&gt;233 put months= quarters=;&lt;BR /&gt;234 end;&lt;BR /&gt;235 run;&lt;/P&gt;
&lt;P&gt;months=1 quarters=1&lt;BR /&gt;months=2 quarters=1&lt;BR /&gt;months=3 quarters=1&lt;BR /&gt;months=4 quarters=2&lt;BR /&gt;months=5 quarters=2&lt;BR /&gt;months=6 quarters=2&lt;BR /&gt;months=7 quarters=3&lt;BR /&gt;months=8 quarters=3&lt;BR /&gt;months=9 quarters=3&lt;BR /&gt;months=10 quarters=4&lt;BR /&gt;months=11 quarters=4&lt;BR /&gt;months=12 quarters=4&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 13 Sep 2017 19:42:48 GMT</pubDate>
    <dc:creator>ErikLund_Jensen</dc:creator>
    <dc:date>2017-09-13T19:42:48Z</dc:date>
    <item>
      <title>How to change Months into Quarters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-change-Months-into-Quarters/m-p/395538#M95420</link>
      <description>&lt;P&gt;Hi all, I have series of months numbers and I want to change it into quarters number, but I don't have the data in date format so I can't use quarter() statement.&lt;/P&gt;&lt;P&gt;Like following: what I want is the Quarters column&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Months&lt;/TD&gt;&lt;TD&gt;Quarters&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;9&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;11&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;13&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;14&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;15&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;16&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;17&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;18&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;19&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;20&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks so much &amp;nbsp;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2017 13:29:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-change-Months-into-Quarters/m-p/395538#M95420</guid>
      <dc:creator>Linmuxi</dc:creator>
      <dc:date>2017-09-13T13:29:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to change Months into Quarters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-change-Months-into-Quarters/m-p/395541#M95422</link>
      <description>&lt;P&gt;UNTESTED CODE&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;quarters=floor(mod(months,12)/3)+1;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Sep 2017 13:37:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-change-Months-into-Quarters/m-p/395541#M95422</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2017-09-13T13:37:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to change Months into Quarters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-change-Months-into-Quarters/m-p/395630#M95455</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/111514"&gt;@Linmuxi&lt;/a&gt;&amp;nbsp; if i understood you-&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; have(drop=Quarters);&lt;/P&gt;&lt;P&gt;input Months&amp;nbsp;&amp;nbsp;&amp;nbsp; Quarters;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;0&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;3&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&lt;/P&gt;&lt;P&gt;4&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&lt;/P&gt;&lt;P&gt;5&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&lt;/P&gt;&lt;P&gt;6&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&lt;/P&gt;&lt;P&gt;7&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&lt;/P&gt;&lt;P&gt;8&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&lt;/P&gt;&lt;P&gt;9&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&lt;/P&gt;&lt;P&gt;10&amp;nbsp;&amp;nbsp; 4&lt;/P&gt;&lt;P&gt;11&amp;nbsp;&amp;nbsp; 4&lt;/P&gt;&lt;P&gt;12&amp;nbsp;&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;13&amp;nbsp;&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;14&amp;nbsp;&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;15&amp;nbsp;&amp;nbsp; 2&lt;/P&gt;&lt;P&gt;16&amp;nbsp;&amp;nbsp; 2&lt;/P&gt;&lt;P&gt;17&amp;nbsp;&amp;nbsp; 2&lt;/P&gt;&lt;P&gt;18&amp;nbsp;&amp;nbsp; 3&lt;/P&gt;&lt;P&gt;19&amp;nbsp;&amp;nbsp; 3&lt;/P&gt;&lt;P&gt;20&amp;nbsp;&amp;nbsp; 3&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; want;&lt;/P&gt;&lt;P&gt;do _n_=&lt;STRONG&gt;1&lt;/STRONG&gt; by &lt;STRONG&gt;1&lt;/STRONG&gt; until(_n_=&lt;STRONG&gt;12&lt;/STRONG&gt;);&lt;/P&gt;&lt;P&gt;set have end=last;&lt;/P&gt;&lt;P&gt;if _n_=&lt;STRONG&gt;1&lt;/STRONG&gt; then quarters=&lt;STRONG&gt;1&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;output;&lt;/P&gt;&lt;P&gt;if mod(_n_,&lt;STRONG&gt;3&lt;/STRONG&gt;)=&lt;STRONG&gt;0&lt;/STRONG&gt; then quarters+&lt;STRONG&gt;1&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;end;&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;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2017 16:53:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-change-Months-into-Quarters/m-p/395630#M95455</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2017-09-13T16:53:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to change Months into Quarters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-change-Months-into-Quarters/m-p/395741#M95491</link>
      <description>&lt;P&gt;hi linmuxi&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this case uou&amp;nbsp;could use the QTR function by translating the month to a date by using the MDY funtion with constants as values for day and year. Any year and any day (less than 29) will give the same result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;230 data _null_;&lt;BR /&gt;231 do months = 1 to 12;&lt;BR /&gt;232 quarters = qtr(mdy(months,1,2017));&lt;BR /&gt;233 put months= quarters=;&lt;BR /&gt;234 end;&lt;BR /&gt;235 run;&lt;/P&gt;
&lt;P&gt;months=1 quarters=1&lt;BR /&gt;months=2 quarters=1&lt;BR /&gt;months=3 quarters=1&lt;BR /&gt;months=4 quarters=2&lt;BR /&gt;months=5 quarters=2&lt;BR /&gt;months=6 quarters=2&lt;BR /&gt;months=7 quarters=3&lt;BR /&gt;months=8 quarters=3&lt;BR /&gt;months=9 quarters=3&lt;BR /&gt;months=10 quarters=4&lt;BR /&gt;months=11 quarters=4&lt;BR /&gt;months=12 quarters=4&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2017 19:42:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-change-Months-into-Quarters/m-p/395741#M95491</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2017-09-13T19:42:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to change Months into Quarters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-change-Months-into-Quarters/m-p/395755#M95496</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12887"&gt;@ErikLund_Jensen&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;hi linmuxi&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this case uou&amp;nbsp;could use the QTR function by translating the month to a date by using the MDY funtion with constants as values for day and year. Any year and any day (less than 29) will give the same result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;230 data _null_;&lt;BR /&gt;231 do months = 1 to 12;&lt;BR /&gt;232 quarters = qtr(mdy(months,1,2017));&lt;BR /&gt;233 put months= quarters=;&lt;BR /&gt;234 end;&lt;BR /&gt;235 run;&lt;/P&gt;
&lt;P&gt;months=1 quarters=1&lt;BR /&gt;months=2 quarters=1&lt;BR /&gt;months=3 quarters=1&lt;BR /&gt;months=4 quarters=2&lt;BR /&gt;months=5 quarters=2&lt;BR /&gt;months=6 quarters=2&lt;BR /&gt;months=7 quarters=3&lt;BR /&gt;months=8 quarters=3&lt;BR /&gt;months=9 quarters=3&lt;BR /&gt;months=10 quarters=4&lt;BR /&gt;months=11 quarters=4&lt;BR /&gt;months=12 quarters=4&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;But the original request had months up to 20; and furthermore&amp;nbsp;month 0 is in quarter 1, month 3 is in quarter 2, month 12 is in quarter 1, &lt;EM&gt;etc&lt;/EM&gt;. Your answer doesn't handle this.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2017 20:24:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-change-Months-into-Quarters/m-p/395755#M95496</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2017-09-13T20:24:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to change Months into Quarters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-change-Months-into-Quarters/m-p/395851#M95539</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* 
Try this one. 
#1. Build lookup table
*/


data HAVE;
  do months= 0 to 71;
    output;
  end;
run;

/*#2 define quater */

data WANT;
  set HAVE;
  TAG+1;
  if TAG=13 then TAG=1;
    else if 4&amp;lt;=TAG &amp;lt;=6 then QUARTERS=2;
    else if 7&amp;lt;=TAG &amp;lt;=9 then QUARTERS=3;
    else if 10&amp;lt;=TAG &amp;lt;=12 then QUARTERS=4;

retain TAG;
run;

/*
#3 I intentionally left the variable TAG for you to see that no matter what the value of MONTHS tag will be
between 1 and 12

data set WANT may serve as your lookup table and you can use it to merge or join with other 
tables whenever you need to derive the quarter 


Here's how: 
*/

data ACTUAL;
  input months 8.;
cards;
8
4
12
17
55
1
3
7
;
run;
proc sql;
  create table actual_with_qtr as
  select a.*, b.quarters from ACTUAL a left join WANT b
  on a.months=b.months;
quit;

/*Hope this helps*/&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Sep 2017 04:53:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-change-Months-into-Quarters/m-p/395851#M95539</guid>
      <dc:creator>ShiroAmada</dc:creator>
      <dc:date>2017-09-14T04:53:19Z</dc:date>
    </item>
  </channel>
</rss>

