<?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 date conversion in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/date-conversion/m-p/398291#M96327</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to organise a lot of dates into a standard format e.g. July 6, 1985. However, I've been sent dates in non-SAS format. This is my code so far, but I can't find the right informat for&amp;nbsp;SAS to convert it to the standard format. The output I'd like to have for my code examples is July 4, 2015 and July 6, 2014.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data practice;&lt;/P&gt;&lt;P&gt;input #1 @1 dates$12.;&lt;BR /&gt;Birth_date = input(dates,informat.);&lt;BR /&gt;datalines;&lt;BR /&gt;20154Jul&lt;BR /&gt;0762014&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;ods listing;&lt;BR /&gt;proc print data=practice;&lt;BR /&gt;run;&lt;BR /&gt;proc print data=practice;&lt;BR /&gt;format Birth_date worddate.;&lt;BR /&gt;run;&lt;/P&gt;</description>
    <pubDate>Sat, 23 Sep 2017 13:07:06 GMT</pubDate>
    <dc:creator>harcluna</dc:creator>
    <dc:date>2017-09-23T13:07:06Z</dc:date>
    <item>
      <title>date conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/date-conversion/m-p/398291#M96327</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to organise a lot of dates into a standard format e.g. July 6, 1985. However, I've been sent dates in non-SAS format. This is my code so far, but I can't find the right informat for&amp;nbsp;SAS to convert it to the standard format. The output I'd like to have for my code examples is July 4, 2015 and July 6, 2014.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data practice;&lt;/P&gt;&lt;P&gt;input #1 @1 dates$12.;&lt;BR /&gt;Birth_date = input(dates,informat.);&lt;BR /&gt;datalines;&lt;BR /&gt;20154Jul&lt;BR /&gt;0762014&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;ods listing;&lt;BR /&gt;proc print data=practice;&lt;BR /&gt;run;&lt;BR /&gt;proc print data=practice;&lt;BR /&gt;format Birth_date worddate.;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Sat, 23 Sep 2017 13:07:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/date-conversion/m-p/398291#M96327</guid>
      <dc:creator>harcluna</dc:creator>
      <dc:date>2017-09-23T13:07:06Z</dc:date>
    </item>
    <item>
      <title>Re: date conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/date-conversion/m-p/398293#M96328</link>
      <description>&lt;P&gt;There are no informats that can read those values as dates. Either read it as a string and convert with code or create your own custom informat. &amp;nbsp;It might be hard to define a format that handles every possible input string. So perhaps a better approach is to just analyze the data you have and see what values existing (like the two you posted) that are confusing and then generate a format that handles those specific values.&lt;/P&gt;
&lt;P&gt;So for example you could start by trying to convert your strings using the ANYDTDTE forma.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  input str $12. ;
  date = input(str,??anydtdte12.);
  format date yymmdd10. ;
datalines;
2015-07-04
04JUL2015
4jul15
07042015
20154Jul
0742014
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could then see what strings did not yield valid dates. For example you could look for missing, but you could also look for really strnage values like way in the past or far into the future.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq order=data ;
 where missing(date);
 tables str ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you can decide what date you want those strings to mean and add them into a custom format.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format ;
 invalue mydt (upcase default=40)
   '20154JUL'='04JUL2015'd
   '0742014' ='04JUL2014'd
   other=[anydtdte.]
 ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you can use that to convert your strings to dates.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  input str $12. ;
  date = input(str,??mydt12.);
  format date yymmdd10. ;
datalines;
2015-07-04
04JUL2015
4jul15
07042015
20154Jul
0742014
;
proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs    str                 date

 1     2015-07-04    2015-07-04
 2     04JUL2015     2015-07-04
 3     4jul15        2015-07-04
 4     07042015      2015-07-04
 5     20154Jul      2015-07-04
 6     0742014       2014-07-04&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 23 Sep 2017 13:45:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/date-conversion/m-p/398293#M96328</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-09-23T13:45:20Z</dc:date>
    </item>
  </channel>
</rss>

