<?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 Reading Excel file with mixture of date formats in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Reading-Excel-file-with-mixture-of-date-formats/m-p/515340#M2895</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have received an Excel file, where the date column is written in two formats: 7/nov/13 and 21oct2010. I can manually change the three month letter into /mon/ format in Excel.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I would like to do that only in SAS. When I use&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Libname abc xlsx "~\abc.xlsx";

data abc;
	set abc.Sheet1;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The date column returns&amp;nbsp;SAS Output 41585 and&amp;nbsp;&lt;SPAN&gt;21oct2010. I check with proc contents and the format for the date is char.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Do you have any idea of reading mixture date formats?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thank you for reading my question!&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 22 Nov 2018 12:58:23 GMT</pubDate>
    <dc:creator>trungdungtran</dc:creator>
    <dc:date>2018-11-22T12:58:23Z</dc:date>
    <item>
      <title>Reading Excel file with mixture of date formats</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Reading-Excel-file-with-mixture-of-date-formats/m-p/515340#M2895</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have received an Excel file, where the date column is written in two formats: 7/nov/13 and 21oct2010. I can manually change the three month letter into /mon/ format in Excel.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I would like to do that only in SAS. When I use&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Libname abc xlsx "~\abc.xlsx";

data abc;
	set abc.Sheet1;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The date column returns&amp;nbsp;SAS Output 41585 and&amp;nbsp;&lt;SPAN&gt;21oct2010. I check with proc contents and the format for the date is char.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Do you have any idea of reading mixture date formats?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thank you for reading my question!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Nov 2018 12:58:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Reading-Excel-file-with-mixture-of-date-formats/m-p/515340#M2895</guid>
      <dc:creator>trungdungtran</dc:creator>
      <dc:date>2018-11-22T12:58:23Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Excel file with mixture of date formats</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Reading-Excel-file-with-mixture-of-date-formats/m-p/515343#M2896</link>
      <description>&lt;P&gt;Save as CSV, read in that variable using the anydtdte. informat.&lt;/P&gt;
&lt;P&gt;Save as CSV, read in as text, then convert.&lt;/P&gt;
&lt;P&gt;Fix the bad data at source.&lt;/P&gt;
&lt;P&gt;Ditch Excel.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Nov 2018 13:07:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Reading-Excel-file-with-mixture-of-date-formats/m-p/515343#M2896</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-11-22T13:07:05Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Excel file with mixture of date formats</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Reading-Excel-file-with-mixture-of-date-formats/m-p/515347#M2897</link>
      <description>&lt;P&gt;I'd return such **** to sender.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since you now have it as character in SAS, this means the following:&lt;/P&gt;
&lt;P&gt;- 21oct2010 is stored in Excel as a string, causing the column to be considered character by libname xlsx&lt;/P&gt;
&lt;P&gt;- therefore you get the raw numeric value of the real Excel date converted to a string in the same column&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can conditionally convert such values:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input column :$10.;
cards;
21oct2010
41585
;
run;

data want;
set have;
if length(column) &amp;gt; 5
then mydate = input(column,date9.);
else mydate = input(column,5.) + '30dec1899'd;
format mydate e8601da10.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This will of course work only until the sender comes up with another surprise for you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;Edit: corrected the date offset for Excel according to &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;'s advice.&lt;/FONT&gt;&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Nov 2018 06:56:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Reading-Excel-file-with-mixture-of-date-formats/m-p/515347#M2897</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-11-23T06:56:48Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Excel file with mixture of date formats</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Reading-Excel-file-with-mixture-of-date-formats/m-p/515481#M2929</link>
      <description>&lt;P&gt;Great answer, except the conversion factor is a little off.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) SAS considers zero the first day and Excel considers the first day as number one.&lt;/P&gt;
&lt;P&gt;2) Excel thinks that 1900 was a leap year.&lt;/P&gt;
&lt;P&gt;So you can either use '30DEC1899'd as your constant or subtract an additional 2 days.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Nov 2018 05:06:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Reading-Excel-file-with-mixture-of-date-formats/m-p/515481#M2929</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-11-23T05:06:06Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Excel file with mixture of date formats</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Reading-Excel-file-with-mixture-of-date-formats/m-p/515495#M2936</link>
      <description>&lt;P&gt;Good catch, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;!&lt;/P&gt;</description>
      <pubDate>Fri, 23 Nov 2018 06:54:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Reading-Excel-file-with-mixture-of-date-formats/m-p/515495#M2936</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-11-23T06:54:34Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Excel file with mixture of date formats</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Reading-Excel-file-with-mixture-of-date-formats/m-p/515916#M3040</link>
      <description>&lt;P&gt;Thank you all for your help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will try to ask the source to fix the column first, otherwise the solution here is perfect.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Nov 2018 08:41:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Reading-Excel-file-with-mixture-of-date-formats/m-p/515916#M3040</guid>
      <dc:creator>trungdungtran</dc:creator>
      <dc:date>2018-11-26T08:41:37Z</dc:date>
    </item>
    <item>
      <title>Re: Reading Excel file with mixture of date formats</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Reading-Excel-file-with-mixture-of-date-formats/m-p/515924#M3042</link>
      <description>&lt;P&gt;The goal has to be to reduce the process to the least necessary steps, and to make it error-proof in the sense that the process detects problems at the earliest possible moment.&lt;/P&gt;
&lt;P&gt;The way to do this is to use a stable and reliable data transfer format (which implicitly disqualifies Excel files), and data steps that are custom-written to the file specification and will throw an error when unexpected data (unexpected either through content or format) is fed into them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All my ETL jobs follow this guideline, and the only problems that "slip through" are of a semantic type where completely plausible data is given that later is found to be logically defective.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Nov 2018 09:01:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Reading-Excel-file-with-mixture-of-date-formats/m-p/515924#M3042</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-11-26T09:01:42Z</dc:date>
    </item>
  </channel>
</rss>

