<?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: Importing CSV with different date formats in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Importing-CSV-with-different-date-formats/m-p/387457#M92900</link>
    <description>&lt;P&gt;I'll preface my suggestion with first set the datestyle option to MDY so that SAS will know how to read ambiguous dates. e.g.:&lt;/P&gt;
&lt;PRE&gt;options datestyle=mdy;
data want;
  input date anydtdte10.;
  format date date9.;
  cards;
2012-04-15
2014-5-6
6/8/2013
7/9/2014
08/12/2015
;
&lt;/PRE&gt;
&lt;P&gt;I prefer that over looking for particular characters in particular columns since, sometimes, people will enter 1 or 2 digit months or days.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 11 Aug 2017 18:35:17 GMT</pubDate>
    <dc:creator>art297</dc:creator>
    <dc:date>2017-08-11T18:35:17Z</dc:date>
    <item>
      <title>Importing CSV with different date formats</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-CSV-with-different-date-formats/m-p/387440#M92895</link>
      <description>&lt;P&gt;I am trying to import a CSV file that has a date variable. Some of the dates are in the yyyy-mm-dd format and others are in mm/dd/yyyy format. How can I import using infile without getting an error?&lt;/P&gt;</description>
      <pubDate>Fri, 11 Aug 2017 17:57:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-CSV-with-different-date-formats/m-p/387440#M92895</guid>
      <dc:creator>priscilabaddouh</dc:creator>
      <dc:date>2017-08-11T17:57:14Z</dc:date>
    </item>
    <item>
      <title>Re: Importing CSV with different date formats</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-CSV-with-different-date-formats/m-p/387447#M92896</link>
      <description>&lt;P&gt;I would try importing the field using the anydtdte. informat&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Aug 2017 18:07:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-CSV-with-different-date-formats/m-p/387447#M92896</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-08-11T18:07:46Z</dc:date>
    </item>
    <item>
      <title>Re: Importing CSV with different date formats</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-CSV-with-different-date-formats/m-p/387452#M92897</link>
      <description>&lt;P&gt;Read into a character variable, and then convert conditionally, depending on the position of the delimiters:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if substr(charvar,5,1) = '-' then datevar = input(charvar,yymmdd10.);
else if substr(charvar,3,1) = '/' then datevar = input(charvar,mmddyy10.);
else put "invalid date format detected";&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 11 Aug 2017 18:18:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-CSV-with-different-date-formats/m-p/387452#M92897</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-08-11T18:18:41Z</dc:date>
    </item>
    <item>
      <title>Re: Importing CSV with different date formats</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-CSV-with-different-date-formats/m-p/387457#M92900</link>
      <description>&lt;P&gt;I'll preface my suggestion with first set the datestyle option to MDY so that SAS will know how to read ambiguous dates. e.g.:&lt;/P&gt;
&lt;PRE&gt;options datestyle=mdy;
data want;
  input date anydtdte10.;
  format date date9.;
  cards;
2012-04-15
2014-5-6
6/8/2013
7/9/2014
08/12/2015
;
&lt;/PRE&gt;
&lt;P&gt;I prefer that over looking for particular characters in particular columns since, sometimes, people will enter 1 or 2 digit months or days.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Aug 2017 18:35:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-CSV-with-different-date-formats/m-p/387457#M92900</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-08-11T18:35:17Z</dc:date>
    </item>
    <item>
      <title>Re: Importing CSV with different date formats</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-CSV-with-different-date-formats/m-p/387522#M92916</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/146623"&gt;@priscilabaddouh&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;To post a 3rd option which is kind-of in the middle of what&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13711"&gt;@art297&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;suggest.&lt;/P&gt;
&lt;P&gt;You could create your own informat using a regular expression and then use pattern specific informats. This is a bit more complicated than using the anydtdte. informat but it gives you full control&amp;nbsp;over the treatment for&amp;nbsp;different text patterns.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
  invalue mixedDates
    '/-/'  (regexp) = [yymmdd10.] 
    '/\//' (regexp) = [mmddyy10.] 
    other=_error_
  ;
run; 


data want;
  input date mixedDates.;
  format date date9.;
  cards;
2012-04-15
2014-5-6
6/8/2013
7/9/2014
08/12/2015
01jan2017
;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Using a RegEx in an informat requires a current SAS version.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/proc/70377/HTML/default/viewer.htm#n1jriq5xib5j45n1pwpwzk311v0p.htm&amp;nbsp;" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/proc/70377/HTML/default/viewer.htm#n1jriq5xib5j45n1pwpwzk311v0p.htm&amp;nbsp;&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 12 Aug 2017 01:06:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-CSV-with-different-date-formats/m-p/387522#M92916</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-08-12T01:06:26Z</dc:date>
    </item>
    <item>
      <title>Re: Importing CSV with different date formats</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-CSV-with-different-date-formats/m-p/388333#M93123</link>
      <description>Thank you.</description>
      <pubDate>Tue, 15 Aug 2017 22:17:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-CSV-with-different-date-formats/m-p/388333#M93123</guid>
      <dc:creator>priscilabaddouh</dc:creator>
      <dc:date>2017-08-15T22:17:18Z</dc:date>
    </item>
    <item>
      <title>Re: Importing CSV with different date formats</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-CSV-with-different-date-formats/m-p/388335#M93125</link>
      <description>&lt;P&gt;Thank you everyone.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Aug 2017 22:18:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-CSV-with-different-date-formats/m-p/388335#M93125</guid>
      <dc:creator>priscilabaddouh</dc:creator>
      <dc:date>2017-08-15T22:18:08Z</dc:date>
    </item>
  </channel>
</rss>

