<?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: Find year and months from quarterly date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Find-year-and-months-from-quarterly-date/m-p/702241#M215085</link>
    <description>&lt;P&gt;Once you've generated a sas date from the reporting_date macrovar, the catx function will easily generate the csv list of months:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let Reporting_date=20171231;

data _null_;
  d0=intnx('qtr',input("&amp;amp;reporting_date",yymmdd8.),0,'BEG');
  m0=month(d0);
  year=year(d0);
  length months $8;
  months=catx(',',m0,m0+1,m0+2);
  put year= months=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now for dates in Jan through Sep, the month list won't have leading zeroes (i.e.20170331 generates 1,2,3 not 01,02,03).&amp;nbsp; If you want leading zeroes, then use&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; months=catx(',',put(m0,z2.),put(m0+1,z2.),put(m0+2,z2.));&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 29 Nov 2020 06:09:06 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2020-11-29T06:09:06Z</dc:date>
    <item>
      <title>Find year and months from quarterly date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-year-and-months-from-quarterly-date/m-p/702158#M215049</link>
      <description>&lt;P&gt;I've a macro variable and it will always have a quarter ending reporting date. Now I want to find the year and months value from that macro variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%let Reporting_date=20171231;&lt;/PRE&gt;
&lt;P&gt;Excepted Results: I want to create a variables as below with the excepted values and it should be numeric.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Year=2017&lt;/P&gt;
&lt;P&gt;Months=10,11,12&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help?&lt;/P&gt;</description>
      <pubDate>Sat, 28 Nov 2020 06:21:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-year-and-months-from-quarterly-date/m-p/702158#M215049</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2020-11-28T06:21:01Z</dc:date>
    </item>
    <item>
      <title>Re: Find year and months from quarterly date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-year-and-months-from-quarterly-date/m-p/702159#M215050</link>
      <description>&lt;P&gt;You can try to use&amp;nbsp; this way :&lt;/P&gt;&lt;P&gt;data test ;&lt;BR /&gt;year=year(input("&amp;amp;Reporting_date",yymmdd8.));&lt;BR /&gt;months=month(input("&amp;amp;Reporting_date",yymmdd8.));&lt;BR /&gt;put year=/months=;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Sat, 28 Nov 2020 06:59:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-year-and-months-from-quarterly-date/m-p/702159#M215050</guid>
      <dc:creator>Hnsqwzc0813</dc:creator>
      <dc:date>2020-11-28T06:59:54Z</dc:date>
    </item>
    <item>
      <title>Re: Find year and months from quarterly date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-year-and-months-from-quarterly-date/m-p/702160#M215051</link>
      <description>&lt;P&gt;"10,11,12" cannot be stored as a number.&lt;/P&gt;
&lt;P&gt;BTW, macro variables are always text.&lt;/P&gt;</description>
      <pubDate>Sat, 28 Nov 2020 07:05:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-year-and-months-from-quarterly-date/m-p/702160#M215051</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-11-28T07:05:01Z</dc:date>
    </item>
    <item>
      <title>Re: Find year and months from quarterly date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-year-and-months-from-quarterly-date/m-p/702164#M215053</link>
      <description>I'm fine if months can be stored as text&lt;BR /&gt;</description>
      <pubDate>Sat, 28 Nov 2020 08:37:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-year-and-months-from-quarterly-date/m-p/702164#M215053</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2020-11-28T08:37:57Z</dc:date>
    </item>
    <item>
      <title>Re: Find year and months from quarterly date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-year-and-months-from-quarterly-date/m-p/702165#M215054</link>
      <description>I believe month function returns only month value from the date. But I need&lt;BR /&gt;the month values of the quarter ending reporting date.&lt;BR /&gt;&lt;BR /&gt;I need month values as 10,11,12 if date is 20171231&lt;BR /&gt;</description>
      <pubDate>Sat, 28 Nov 2020 08:41:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-year-and-months-from-quarterly-date/m-p/702165#M215054</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2020-11-28T08:41:57Z</dc:date>
    </item>
    <item>
      <title>Re: Find year and months from quarterly date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-year-and-months-from-quarterly-date/m-p/702167#M215056</link>
      <description>&lt;P&gt;Use a data _null_ step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
call symputx('year',substr("&amp;amp;reporting_date",1,4));
select (substr("&amp;amp;reporting_date",5,2));
  when ("01","02","03") months = "01,02,03";
  when ("04","05","06") months = "04,05,06";
  when ("07","08","09") months = "07,08,09";
  when ("10","11","12") months = "10,11,12";
end;
call symputx('months',months);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 28 Nov 2020 09:02:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-year-and-months-from-quarterly-date/m-p/702167#M215056</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-11-28T09:02:13Z</dc:date>
    </item>
    <item>
      <title>Re: Find year and months from quarterly date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-year-and-months-from-quarterly-date/m-p/702229#M215082</link>
      <description>&lt;P&gt;Essentially, this is a look up of sorts so can use INTNX() + loop, SELECT/IF/CASE statements, formats, lookup table merge, a custom function, or temporary array. The optimal solution usually depends on what you're doing next.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 29 Nov 2020 01:37:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-year-and-months-from-quarterly-date/m-p/702229#M215082</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-11-29T01:37:15Z</dc:date>
    </item>
    <item>
      <title>Re: Find year and months from quarterly date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-year-and-months-from-quarterly-date/m-p/702241#M215085</link>
      <description>&lt;P&gt;Once you've generated a sas date from the reporting_date macrovar, the catx function will easily generate the csv list of months:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let Reporting_date=20171231;

data _null_;
  d0=intnx('qtr',input("&amp;amp;reporting_date",yymmdd8.),0,'BEG');
  m0=month(d0);
  year=year(d0);
  length months $8;
  months=catx(',',m0,m0+1,m0+2);
  put year= months=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now for dates in Jan through Sep, the month list won't have leading zeroes (i.e.20170331 generates 1,2,3 not 01,02,03).&amp;nbsp; If you want leading zeroes, then use&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; months=catx(',',put(m0,z2.),put(m0+1,z2.),put(m0+2,z2.));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 29 Nov 2020 06:09:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-year-and-months-from-quarterly-date/m-p/702241#M215085</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-11-29T06:09:06Z</dc:date>
    </item>
    <item>
      <title>Re: Find year and months from quarterly date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-year-and-months-from-quarterly-date/m-p/702284#M215092</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let Reporting_date=20171231;

data have;
year=%substr(&amp;amp;Reporting_date,1,4);
temp=%substr(&amp;amp;Reporting_date,5,2);
month=catx(',',temp-2,temp-1,temp);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 29 Nov 2020 11:23:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-year-and-months-from-quarterly-date/m-p/702284#M215092</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-11-29T11:23:16Z</dc:date>
    </item>
    <item>
      <title>Re: Find year and months from quarterly date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-year-and-months-from-quarterly-date/m-p/702380#M215118</link>
      <description>&lt;P&gt;You can use qtr function and ' if then ' again&lt;/P&gt;&lt;P&gt;%let Reporting_date=20171231;&lt;BR /&gt;data test ;&lt;BR /&gt;length months $8;&lt;BR /&gt;year=year(input("&amp;amp;Reporting_date",yymmdd8.));&lt;BR /&gt;if qtr(input("&amp;amp;Reporting_date",yymmdd8.))=1 then months='1,2,3';&lt;BR /&gt;else if qtr(input("&amp;amp;Reporting_date",yymmdd8.))=2 then months='4,5,6';&lt;BR /&gt;else if qtr(input("&amp;amp;Reporting_date",yymmdd8.))=3 then months='7,8,9';&lt;BR /&gt;else if qtr(input("&amp;amp;Reporting_date",yymmdd8.))=4 then months='10,11,12';&lt;BR /&gt;put year=/months=;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Nov 2020 02:05:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-year-and-months-from-quarterly-date/m-p/702380#M215118</guid>
      <dc:creator>Hnsqwzc0813</dc:creator>
      <dc:date>2020-11-30T02:05:41Z</dc:date>
    </item>
  </channel>
</rss>

