<?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 How convert month spelling into numeric in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-convert-month-spelling-into-numeric/m-p/565492#M158785</link>
    <description>Data ex;&lt;BR /&gt;Date='april';&lt;BR /&gt;New=input(date,monname.);&lt;BR /&gt;Run;&lt;BR /&gt;&lt;BR /&gt;If I run above I am getting error there no informat I know&lt;BR /&gt;But how to convert&lt;BR /&gt;</description>
    <pubDate>Wed, 12 Jun 2019 09:42:51 GMT</pubDate>
    <dc:creator>thanikondharish</dc:creator>
    <dc:date>2019-06-12T09:42:51Z</dc:date>
    <item>
      <title>How convert month spelling into numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-convert-month-spelling-into-numeric/m-p/565492#M158785</link>
      <description>Data ex;&lt;BR /&gt;Date='april';&lt;BR /&gt;New=input(date,monname.);&lt;BR /&gt;Run;&lt;BR /&gt;&lt;BR /&gt;If I run above I am getting error there no informat I know&lt;BR /&gt;But how to convert&lt;BR /&gt;</description>
      <pubDate>Wed, 12 Jun 2019 09:42:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-convert-month-spelling-into-numeric/m-p/565492#M158785</guid>
      <dc:creator>thanikondharish</dc:creator>
      <dc:date>2019-06-12T09:42:51Z</dc:date>
    </item>
    <item>
      <title>Re: How convert month spelling into numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-convert-month-spelling-into-numeric/m-p/565494#M158786</link>
      <description>&lt;P&gt;The Format monname returns the name of month and expects a valid sas-date as input.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't think that a format translating month names to numbers exists.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could do something like:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;concatenate '01', the first three chars of the month-name and a year&lt;/LI&gt;
&lt;LI&gt;use that string in input-function with date9 as format to get a date&lt;/LI&gt;
&lt;LI&gt;&lt;STRIKE&gt;then use put-function with the date and monname-format&lt;/STRIKE&gt; don't know why is thought that the format monname is of any use here ... &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt; pointed out that using month-function is the tool to be used&lt;BR /&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Easier way: write a format for doing the conversation or use Google ...&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jun 2019 11:34:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-convert-month-spelling-into-numeric/m-p/565494#M158786</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-06-12T11:34:04Z</dc:date>
    </item>
    <item>
      <title>Re: How convert month spelling into numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-convert-month-spelling-into-numeric/m-p/565496#M158787</link>
      <description>&lt;P&gt;Use the &lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000201049.htm" target="_self"&gt;Monname Format&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jun 2019 10:04:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-convert-month-spelling-into-numeric/m-p/565496#M158787</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-06-12T10:04:49Z</dc:date>
    </item>
    <item>
      <title>Re: How convert month spelling into numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-convert-month-spelling-into-numeric/m-p/565497#M158788</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/209685"&gt;@thanikondharish&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A date value in SAS is stored as the number of days since 1/1/1960. You then apply a date format for printing so the internal value becomes human readable as a date.&lt;/P&gt;
&lt;P&gt;You can also convert a text string representing a date to a SAS date value. You do this by using the input function together with an informat which instructs SAS how to interpret the source string.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So now if your source string is only a month name: How should SAS "know" which calendar day and year to use for conversion into a SAS date value. If you know this then it's possible to write code. Something like the following would work:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data ex;
  Date='april';
  New=input(cats('01',substr(date,1,3),'2019'),date9.);
  format new date9.;
Run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 12 Jun 2019 10:07:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-convert-month-spelling-into-numeric/m-p/565497#M158788</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-06-12T10:07:32Z</dc:date>
    </item>
    <item>
      <title>Re: How convert month spelling into numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-convert-month-spelling-into-numeric/m-p/565498#M158789</link>
      <description>&lt;P&gt;If your months followed SAS conventions, you could use a SAS-supplied informat:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
month_text = "apr";
month_num = month(input(strip(month_text) !! '2018',monyy10.));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If at least the first three letters followed SAS conventions, you can use substr():&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
month_text = "april";
month_num = month(input(substr(month_text,1,3) !! '2018',monyy10.));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If that is not the case, use a select() block in your data step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select (month_text);
.......
  when ('april') month_num = 4;
........
end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 12 Jun 2019 10:13:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-convert-month-spelling-into-numeric/m-p/565498#M158789</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-06-12T10:13:19Z</dc:date>
    </item>
    <item>
      <title>Re: How convert month spelling into numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-convert-month-spelling-into-numeric/m-p/565577#M158818</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/209685"&gt;@thanikondharish&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Data ex;&lt;BR /&gt;Date='april';&lt;BR /&gt;New=input(date,monname.);&lt;BR /&gt;Run;&lt;BR /&gt;&lt;BR /&gt;If I run above I am getting error there no informat I know&lt;BR /&gt;But how to convert&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Sometimes you either have to write if then else/ select code OR create a custom informat.&lt;/P&gt;
&lt;PRE&gt;proc format library = work;
invalue mon (upcase)
"JANUARY" =1                                                                                      
"FEBRUARY" =2                                                                                     
"MARCH" =3                                                                                        
"APRIL" =4                                                                                        
"MAY" =5                                                                                          
"JUNE" =6                                                                                         
"JULY" =7                                                                                         
"AUGUST" =8                                                                                       
"SEPTEMBER" =9                                                                                    
"OCTOBER" =10                                                                                     
"NOVEMBER" =11                                                                                    
"DECEMBER" =12  
other=.
;
run;

Data ex;
  Date='april';
  New= input(date,mon.);
Run;&lt;/PRE&gt;
&lt;P&gt;Note that the UPCASE option on the informat converts any text to upper case before comparing with the values in the range of the informat. That way inconsistent values like 'april' 'April' 'aPRIL' will all get handled.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And after 200+ posts it is time to learn to use the forum tools for posting code and logs such as the code box opened with the forum's {I} or "running man" icon.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jun 2019 14:59:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-convert-month-spelling-into-numeric/m-p/565577#M158818</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-06-12T14:59:22Z</dc:date>
    </item>
  </channel>
</rss>

