<?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: Convert &amp;quot;month_year&amp;quot; and &amp;quot;year_month&amp;quot; string to date in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Convert-quot-month-year-quot-and-quot-year-month-quot-string-to/m-p/185605#M47133</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you are getting values as described I don't think you'll ever find an informat that would read them accurately because of multiple possible interpretations.&lt;/P&gt;&lt;P&gt;You will have to parse the data to some extent and determine which have the leading year and which are following. If the years in question are always 4 digits you might be able to use something like:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if substr(datestring,1,2) in ('19','20') then do; /* if the first 2 characters are 19 or 20 then they can't be months so should be year*/&lt;/P&gt;&lt;P&gt;/* assuming you want a date value you need to assume a day of month, here I use the first day of the month*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; monyear = mdy(input(substr(datestring,5,2),f2.),1,input(substr(datestring,1,4),f4.));&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;else do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; monyear = mdy(input(substr(datestring,1,2),f2.),1,input(substr(datestring,3,4),f4.));&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;format monyear mmyy6.;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 18 Apr 2014 15:05:30 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2014-04-18T15:05:30Z</dc:date>
    <item>
      <title>Convert "month_year" and "year_month" string to date</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Convert-quot-month-year-quot-and-quot-year-month-quot-string-to/m-p/185604#M47132</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi everyone&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10pt; font-family: Arial, sans-serif;"&gt; &lt;/SPAN&gt;&lt;SPAN lang="EN-US" style="font-size: 10pt; font-family: Arial, sans-serif;"&gt;I have a string like "042014" and other like "201404" both meaning April 2014.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN lang="EN-US" style="font-size: 10pt; font-family: Arial, sans-serif;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN lang="EN-US" style="font-size: 10pt; font-family: Arial, sans-serif;"&gt; What I want to do is to convert both ones in some "Month-Year" format, so I can use them in IF-THEN-ELSE statement like &amp;gt; &amp;lt; = etc.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN lang="EN-US" style="font-size: 10pt; font-family: Arial, sans-serif;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN lang="EN-US" style="font-size: 10pt; font-family: Arial, sans-serif;"&gt; In addition: I have imported them in $char6. I do not know if I can import them in date format, like DDMMYY10. because in that case I do not have the days.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN lang="EN-US" style="font-size: 10pt; font-family: Arial, sans-serif;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN lang="EN-US" style="font-size: 10pt; font-family: Arial, sans-serif;"&gt;Thanks and regards from Brazil.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Apr 2014 14:30:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Convert-quot-month-year-quot-and-quot-year-month-quot-string-to/m-p/185604#M47132</guid>
      <dc:creator>anonymous_user</dc:creator>
      <dc:date>2014-04-18T14:30:55Z</dc:date>
    </item>
    <item>
      <title>Re: Convert "month_year" and "year_month" string to date</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Convert-quot-month-year-quot-and-quot-year-month-quot-string-to/m-p/185605#M47133</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you are getting values as described I don't think you'll ever find an informat that would read them accurately because of multiple possible interpretations.&lt;/P&gt;&lt;P&gt;You will have to parse the data to some extent and determine which have the leading year and which are following. If the years in question are always 4 digits you might be able to use something like:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if substr(datestring,1,2) in ('19','20') then do; /* if the first 2 characters are 19 or 20 then they can't be months so should be year*/&lt;/P&gt;&lt;P&gt;/* assuming you want a date value you need to assume a day of month, here I use the first day of the month*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; monyear = mdy(input(substr(datestring,5,2),f2.),1,input(substr(datestring,1,4),f4.));&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;else do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; monyear = mdy(input(substr(datestring,1,2),f2.),1,input(substr(datestring,3,4),f4.));&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;format monyear mmyy6.;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Apr 2014 15:05:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Convert-quot-month-year-quot-and-quot-year-month-quot-string-to/m-p/185605#M47133</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2014-04-18T15:05:30Z</dc:date>
    </item>
    <item>
      <title>Re: Convert "month_year" and "year_month" string to date</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Convert-quot-month-year-quot-and-quot-year-month-quot-string-to/m-p/185606#M47134</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Same like ballard:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;data x;
input date $6.;
cards;
201404
042014
;
run;
data x;
 set x;
 if date in: ('20' '19') then d=input(date||'01',yymmdd10.);
&amp;nbsp; else d=input('01'||date,ddmmyy10.);
&amp;nbsp; format d date.;
run;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Xia Keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 19 Apr 2014 01:50:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Convert-quot-month-year-quot-and-quot-year-month-quot-string-to/m-p/185606#M47134</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2014-04-19T01:50:42Z</dc:date>
    </item>
    <item>
      <title>Re: Convert "month_year" and "year_month" string to date</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Convert-quot-month-year-quot-and-quot-year-month-quot-string-to/m-p/185607#M47135</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks it worked perfectly!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 21 Apr 2014 18:15:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Convert-quot-month-year-quot-and-quot-year-month-quot-string-to/m-p/185607#M47135</guid>
      <dc:creator>anonymous_user</dc:creator>
      <dc:date>2014-04-21T18:15:31Z</dc:date>
    </item>
    <item>
      <title>Re: Convert "month_year" and "year_month" string to date</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Convert-quot-month-year-quot-and-quot-year-month-quot-string-to/m-p/185608#M47136</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Ksharp, like ballard your solution worked perfectly.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 21 Apr 2014 18:17:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Convert-quot-month-year-quot-and-quot-year-month-quot-string-to/m-p/185608#M47136</guid>
      <dc:creator>anonymous_user</dc:creator>
      <dc:date>2014-04-21T18:17:49Z</dc:date>
    </item>
    <item>
      <title>Re: Convert "month_year" and "year_month" string to date</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Convert-quot-month-year-quot-and-quot-year-month-quot-string-to/m-p/185609#M47137</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I would like to suggest that a user informat would make the code look simpler.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;based on the first character of the string, you have a good clue about the more appropriate INFORMAT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This offers an opportunity to demonstrate using informats in the LABEL area of user defined informats.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PROC FORMAT ;&lt;/P&gt;&lt;P&gt;INVALUE mixed_up_date&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; '010000' - '199999' = [mmyyn6.] /* see below */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; '200000' - '299999' = [yymmn6.]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; other = _error_ ;&lt;/P&gt;&lt;P&gt;run ;&lt;/P&gt;&lt;P&gt;proc format&lt;/P&gt;&lt;P&gt;run ;&lt;/P&gt;&lt;P&gt;data x ;&lt;/P&gt;&lt;P&gt;attrib&amp;nbsp; date format=date9. informat= mixed_up_date6. ;&lt;/P&gt;&lt;P&gt;input date ;&lt;/P&gt;&lt;P&gt;cards ;&lt;/P&gt;&lt;P&gt;201404&lt;/P&gt;&lt;P&gt;042014&lt;/P&gt;&lt;P&gt;failure&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Unfortunately, although there is an informat for YYYYMM style dates, there is no informat for MMYYYY&lt;/P&gt;&lt;P&gt;Well, not until someone creates one.&lt;/P&gt;&lt;P&gt;Until SAS Institute do (&lt;EM&gt;is a "birdie" listening?&lt;/EM&gt; ), here is mine (date ranges 2000 to 2100)&lt;/P&gt;&lt;P&gt;data cntlin ;&lt;/P&gt;&lt;P&gt;retain fmtname 'mmyyN'&amp;nbsp; type 'i ' ;&lt;/P&gt;&lt;P&gt;do mm=1 to 12 ;&lt;/P&gt;&lt;P&gt;do yy = 2000 to 2100 ;&lt;/P&gt;&lt;P&gt;start = put( mm*1e4 + yy, z6. ) ;&lt;/P&gt;&lt;P&gt;label = mdy( mm, 1, yy ) ;&lt;/P&gt;&lt;P&gt;output ;&lt;/P&gt;&lt;P&gt;end; end ;&lt;/P&gt;&lt;P&gt;hlo= 'o' ;&lt;/P&gt;&lt;P&gt;call missing( start, label ) ;&lt;/P&gt;&lt;P&gt;output ;&lt;/P&gt;&lt;P&gt;run ;&lt;/P&gt;&lt;P&gt;PROC FORMAT cntlin = cntlin ;&lt;/P&gt;&lt;P&gt;run&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: Peter Crawford&amp;nbsp; (uk time 20:54 22Apr2014)&#xD;
&amp;nbsp;&amp;nbsp; &#xD;
 someone needed to fix my defects = bugs caused by rushed and untested typing.&#xD;
&amp;nbsp; &#xD;
The corrected code has been tested in SAS9.3 and 9.4&#xD;
&#xD;
 &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 Apr 2014 13:44:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Convert-quot-month-year-quot-and-quot-year-month-quot-string-to/m-p/185609#M47137</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2014-04-22T13:44:19Z</dc:date>
    </item>
  </channel>
</rss>

