<?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: extract month in a year using loops in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/extract-month-in-a-year-using-loops/m-p/804234#M316686</link>
    <description>&lt;P&gt;As I mentioned, the MONNAME format is for&amp;nbsp;&lt;EM&gt;date&lt;/EM&gt; values, not&amp;nbsp;&lt;EM&gt;month numbers&lt;/EM&gt;. Please read the documentation.&lt;/P&gt;
&lt;P&gt;And if you want to loop over months, not dates, you will need a different loop. Either DO WHILE and the INTNX function to increment, or a loop from 1 to 12, building dates with the MDY function.&lt;/P&gt;</description>
    <pubDate>Sat, 26 Mar 2022 07:10:25 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2022-03-26T07:10:25Z</dc:date>
    <item>
      <title>extract month in a year using loops</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-month-in-a-year-using-loops/m-p/804224#M316677</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data month;
st='01Jan2010';
enddt='31Dec2010';
do i=st to enddt;
month=intnx('Month',st,i,'same');
output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Required output&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Date	Month
01-Jan-10	Jan
01-Feb-10	Feb
01-Mar-10	Mar
01-Apr-10	Apr
01-May-10	May
01-Jun-10	Jun
01-Jul-10	Jul
01-Aug-10	Aug
01-Sep-10	Sep
01-Oct-10	Oct
01-Nov-10	Nov
01-Dec-10	Dec
&lt;/PRE&gt;</description>
      <pubDate>Sat, 26 Mar 2022 05:20:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-month-in-a-year-using-loops/m-p/804224#M316677</guid>
      <dc:creator>BrahmanandaRao</dc:creator>
      <dc:date>2022-03-26T05:20:52Z</dc:date>
    </item>
    <item>
      <title>Re: extract month in a year using loops</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-month-in-a-year-using-loops/m-p/804229#M316682</link>
      <description>&lt;P&gt;You cannot use character values as start and end of an iterative DO loop.&lt;/P&gt;
&lt;P&gt;To make your strings into date literals, add a trailing d:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;st = '01Jan2010'd;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Use the&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/leforinforref/n0jbl63yy0tktzn1a5hgn7kadtrg.htm" target="_blank" rel="noopener"&gt;MONNAME&lt;/A&gt;&amp;nbsp;format to get the character month from a SAS date value.&lt;/P&gt;</description>
      <pubDate>Sat, 26 Mar 2022 05:34:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-month-in-a-year-using-loops/m-p/804229#M316682</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-03-26T05:34:41Z</dc:date>
    </item>
    <item>
      <title>Re: extract month in a year using loops</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-month-in-a-year-using-loops/m-p/804230#M316683</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data month;
do i= '01Jan2010'd to '31Dec2010'd;
month=put(month((i) ,monname3.));
output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 26 Mar 2022 05:44:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-month-in-a-year-using-loops/m-p/804230#M316683</guid>
      <dc:creator>BrahmanandaRao</dc:creator>
      <dc:date>2022-03-26T05:44:20Z</dc:date>
    </item>
    <item>
      <title>Re: extract month in a year using loops</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-month-in-a-year-using-loops/m-p/804234#M316686</link>
      <description>&lt;P&gt;As I mentioned, the MONNAME format is for&amp;nbsp;&lt;EM&gt;date&lt;/EM&gt; values, not&amp;nbsp;&lt;EM&gt;month numbers&lt;/EM&gt;. Please read the documentation.&lt;/P&gt;
&lt;P&gt;And if you want to loop over months, not dates, you will need a different loop. Either DO WHILE and the INTNX function to increment, or a loop from 1 to 12, building dates with the MDY function.&lt;/P&gt;</description>
      <pubDate>Sat, 26 Mar 2022 07:10:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-month-in-a-year-using-loops/m-p/804234#M316686</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-03-26T07:10:25Z</dc:date>
    </item>
    <item>
      <title>Re: extract month in a year using loops</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-month-in-a-year-using-loops/m-p/804235#M316687</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data date_range;
do Date ='01Jan2010'd to '31Dec2010'd ;
format Date : date11.;
if Date =intnx('month',Date,0,'b')  then output;
end;
run;


data month;
set date_range;
month=put(Date,monname3.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I tried my idea is it hard coded&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 26 Mar 2022 07:42:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-month-in-a-year-using-loops/m-p/804235#M316687</guid>
      <dc:creator>BrahmanandaRao</dc:creator>
      <dc:date>2022-03-26T07:42:39Z</dc:date>
    </item>
    <item>
      <title>Re: extract month in a year using loops</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-month-in-a-year-using-loops/m-p/804236#M316688</link>
      <description>&lt;P&gt;Use a DO WHILE:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;date = '01jan2022'd;
do while (date le '01dec2022'd);
  output;
  date = intnx('month',date,1,'b');
end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 26 Mar 2022 07:53:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-month-in-a-year-using-loops/m-p/804236#M316688</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-03-26T07:53:46Z</dc:date>
    </item>
    <item>
      <title>Re: extract month in a year using loops</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-month-in-a-year-using-loops/m-p/804238#M316689</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dw;
date = '01jan2022'd;
do while (date le '01dec2022'd);
  output;format date month: date11.;
  Month=put(date,monname3.);
  date = intnx('month',date,1,'b');
  end;
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;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As per your code i got output&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Anandkvn_0-1648281725561.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/69823iD7CC3440EDBB73C4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Anandkvn_0-1648281725561.png" alt="Anandkvn_0-1648281725561.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 26 Mar 2022 08:03:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-month-in-a-year-using-loops/m-p/804238#M316689</guid>
      <dc:creator>BrahmanandaRao</dc:creator>
      <dc:date>2022-03-26T08:03:39Z</dc:date>
    </item>
    <item>
      <title>Re: extract month in a year using loops</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-month-in-a-year-using-loops/m-p/804240#M316691</link>
      <description>&lt;P&gt;That's just the order of statements. Fix that.&lt;/P&gt;</description>
      <pubDate>Sat, 26 Mar 2022 08:08:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-month-in-a-year-using-loops/m-p/804240#M316691</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-03-26T08:08:40Z</dc:date>
    </item>
    <item>
      <title>Re: extract month in a year using loops</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-month-in-a-year-using-loops/m-p/804243#M316693</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dw;
date = '01jan2022'd;
do while (date le '01dec2022'd);
Month=put(date,monname3.);
  output;
  format date month: date11.;
  date = intnx('month',date,1,'b');
  end;proc print noobs;
run;


&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Anandkvn_0-1648282654015.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/69824i90E4C1E0DCBD8372/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Anandkvn_0-1648282654015.png" alt="Anandkvn_0-1648282654015.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 26 Mar 2022 08:18:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-month-in-a-year-using-loops/m-p/804243#M316693</guid>
      <dc:creator>BrahmanandaRao</dc:creator>
      <dc:date>2022-03-26T08:18:05Z</dc:date>
    </item>
  </channel>
</rss>

