<?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 Import Data from Excel - DateTime column has mixed values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Import-Data-from-Excel-DateTime-column-has-mixed-values/m-p/985922#M379881</link>
    <description>&lt;P&gt;I have an excel import file that looks like this:&lt;/P&gt;
&lt;DIV id="tinyMceEditor_Hopper_0" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV id="tinyMceEditor_Hopper_4" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="d37c200f-dccf-4d5b-846e-3298861b2844.PNG" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/114085i6DFCA2DA68D553F0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="d37c200f-dccf-4d5b-846e-3298861b2844.PNG" alt="d37c200f-dccf-4d5b-846e-3298861b2844.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt; &lt;/P&gt;
&lt;P&gt;But two values are character even though they look the same so when imported this is what I see&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="1b40bf2f-9afd-4dfc-87ed-d453ba7e24b4.PNG" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/114083iA0B7B747553A2FB4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="1b40bf2f-9afd-4dfc-87ed-d453ba7e24b4.PNG" alt="1b40bf2f-9afd-4dfc-87ed-d453ba7e24b4.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt; Is there a workaround for this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt; &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 03 Apr 2026 16:24:12 GMT</pubDate>
    <dc:creator>_Hopper</dc:creator>
    <dc:date>2026-04-03T16:24:12Z</dc:date>
    <item>
      <title>Import Data from Excel - DateTime column has mixed values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-Data-from-Excel-DateTime-column-has-mixed-values/m-p/985922#M379881</link>
      <description>&lt;P&gt;I have an excel import file that looks like this:&lt;/P&gt;
&lt;DIV id="tinyMceEditor_Hopper_0" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV id="tinyMceEditor_Hopper_4" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="d37c200f-dccf-4d5b-846e-3298861b2844.PNG" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/114085i6DFCA2DA68D553F0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="d37c200f-dccf-4d5b-846e-3298861b2844.PNG" alt="d37c200f-dccf-4d5b-846e-3298861b2844.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt; &lt;/P&gt;
&lt;P&gt;But two values are character even though they look the same so when imported this is what I see&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="1b40bf2f-9afd-4dfc-87ed-d453ba7e24b4.PNG" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/114083iA0B7B747553A2FB4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="1b40bf2f-9afd-4dfc-87ed-d453ba7e24b4.PNG" alt="1b40bf2f-9afd-4dfc-87ed-d453ba7e24b4.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt; Is there a workaround for this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt; &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Apr 2026 16:24:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-Data-from-Excel-DateTime-column-has-mixed-values/m-p/985922#M379881</guid>
      <dc:creator>_Hopper</dc:creator>
      <dc:date>2026-04-03T16:24:12Z</dc:date>
    </item>
    <item>
      <title>Re: Import Data from Excel - DateTime column has mixed values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-Data-from-Excel-DateTime-column-has-mixed-values/m-p/985927#M379882</link>
      <description>&lt;P&gt;When you have both character and numeric values in a column in EXCEL then SAS is forced to define the variable as character.&amp;nbsp; When this happens with DATE or DATETIME values SAS store the actual numeric value EXCEL uses as a normal digit string.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best solution is to fix the Excel file so that all of the values in that column are actual Excel datetime values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But if you are stuck with the file you have just convert the character variable into a new numeric variable.&amp;nbsp; Then adjust for the difference in the way that EXCEL and SAS count days.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  actual_datetime = input(DateTIme,??32.);
  if missing(actual_datetime) then actual_datetime=input(DateTime,anydtdte20.);
  else actual_datetime = dhms(actual_datetime+'30DEC1899'd,0,0,0);
  format actual_datetime datetime19.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So when the value looks like a number then just add the number of days between 1960 and 1900 to adjust for the difference in what day each system thinks is day one (and the fact that Excel thinks 1900 was a leap year) and convert the number of days into number of seconds.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Otherwise just ask SAS to convert the string into a datetime value.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Apr 2026 17:37:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-Data-from-Excel-DateTime-column-has-mixed-values/m-p/985927#M379882</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2026-04-03T17:37:44Z</dc:date>
    </item>
    <item>
      <title>Re: Import Data from Excel - DateTime column has mixed values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-Data-from-Excel-DateTime-column-has-mixed-values/m-p/985957#M379883</link>
      <description>Can you post this excel with this column, so I can test and solve it ?</description>
      <pubDate>Sat, 04 Apr 2026 01:33:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-Data-from-Excel-DateTime-column-has-mixed-values/m-p/985957#M379883</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2026-04-04T01:33:08Z</dc:date>
    </item>
    <item>
      <title>Re: Import Data from Excel - DateTime column has mixed values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-Data-from-Excel-DateTime-column-has-mixed-values/m-p/985958#M379884</link>
      <description>Tom,&lt;BR /&gt;You only take care of date part of it, not time part, right ?</description>
      <pubDate>Sat, 04 Apr 2026 01:39:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-Data-from-Excel-DateTime-column-has-mixed-values/m-p/985958#M379884</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2026-04-04T01:39:05Z</dc:date>
    </item>
    <item>
      <title>Re: Import Data from Excel - DateTime column has mixed values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-Data-from-Excel-DateTime-column-has-mixed-values/m-p/985959#M379885</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Tom,&lt;BR /&gt;You only take care of date part of it, not time part, right ?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;No.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Excel stores time of day as a fraction of day.&amp;nbsp; The DHMS() function converts a fraction of day into the corresponding number of seconds.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Essentially it is doing:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;60*(60*(24*D + H) + M) + S&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 04 Apr 2026 02:51:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-Data-from-Excel-DateTime-column-has-mixed-values/m-p/985959#M379885</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2026-04-04T02:51:55Z</dc:date>
    </item>
    <item>
      <title>Re: Import Data from Excel - DateTime column has mixed values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-Data-from-Excel-DateTime-column-has-mixed-values/m-p/985960#M379886</link>
      <description>&lt;P&gt;Save to a CSV file and read that with a DATA step. Both the "real" and character datetime values will appear in the same format, so you can read them with the E8601DT informat.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Disclaimer: I tested the "save to csv" with LibreOffice on a Mac, but I sincerely hope MS Excel will do the same.&lt;/P&gt;</description>
      <pubDate>Sat, 04 Apr 2026 10:13:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-Data-from-Excel-DateTime-column-has-mixed-values/m-p/985960#M379886</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2026-04-04T10:13:19Z</dc:date>
    </item>
    <item>
      <title>Re: Import Data from Excel - DateTime column has mixed values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-Data-from-Excel-DateTime-column-has-mixed-values/m-p/985967#M379888</link>
      <description>Tom,&lt;BR /&gt;Great. Learn something new.&lt;BR /&gt;So you should use ANYDTDTM. instead of  ANYDTDTE, right ?&lt;BR /&gt;&lt;BR /&gt; actual_datetime=input(DateTime,anydtdte20.);&lt;BR /&gt;---&amp;gt;&lt;BR /&gt; actual_datetime=input(DateTime,anydtdtm20.);</description>
      <pubDate>Sun, 05 Apr 2026 01:24:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-Data-from-Excel-DateTime-column-has-mixed-values/m-p/985967#M379888</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2026-04-05T01:24:06Z</dc:date>
    </item>
    <item>
      <title>Re: Import Data from Excel - DateTime column has mixed values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-Data-from-Excel-DateTime-column-has-mixed-values/m-p/985981#M379889</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Save to a CSV file and read that with a DATA step. Both the "real" and character datetime values will appear in the same format, so you can read them with the E8601DT informat.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Disclaimer: I tested the "save to csv" with LibreOffice on a Mac, but I sincerely hope MS Excel will do the same.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;Used to have to do this about once a week with my last job and Excel save to CSV usually worked except in the pathological cases of one data source that would have a column with cells that were formatted in Excel as currency for part of the column and then dates for the remainder. In which case the solution was to set the&amp;nbsp;&lt;STRONG&gt;entire column&lt;/STRONG&gt; of the Excel source to the proper appearance before exporting to CSV.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 05 Apr 2026 17:21:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-Data-from-Excel-DateTime-column-has-mixed-values/m-p/985981#M379889</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2026-04-05T17:21:51Z</dc:date>
    </item>
    <item>
      <title>Re: Import Data from Excel - DateTime column has mixed values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-Data-from-Excel-DateTime-column-has-mixed-values/m-p/986023#M379893</link>
      <description>&lt;P&gt;Will this approach still work if the supplier gets their act together and has the values formatted the correct way the next time around? What I want is a permanent solution not one that fixes this issue and then the issue appears again when (if) the input file is corrected.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PS: I'm not allowed to modify the source data (e.g., save it as csv). I have to use it as is.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Apr 2026 13:19:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-Data-from-Excel-DateTime-column-has-mixed-values/m-p/986023#M379893</guid>
      <dc:creator>_Hopper</dc:creator>
      <dc:date>2026-04-06T13:19:27Z</dc:date>
    </item>
    <item>
      <title>Re: Import Data from Excel - DateTime column has mixed values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-Data-from-Excel-DateTime-column-has-mixed-values/m-p/986044#M379896</link>
      <description>&lt;P&gt;Yes&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Apr 2026 18:45:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-Data-from-Excel-DateTime-column-has-mixed-values/m-p/986044#M379896</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2026-04-06T18:45:52Z</dc:date>
    </item>
    <item>
      <title>Re: Import Data from Excel - DateTime column has mixed values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-Data-from-Excel-DateTime-column-has-mixed-values/m-p/986045#M379897</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/436465"&gt;@_Hopper&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Will this approach still work if the supplier gets their act together and has the values formatted the correct way the next time around? What I want is a permanent solution not one that fixes this issue and then the issue appears again when (if) the input file is corrected.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PS: I'm not allowed to modify the source data (e.g., save it as csv). I have to use it as is.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;No.&amp;nbsp; In that case you will need a little more logic to detect if the DateTime variable is numeric or character.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example you might use this&amp;nbsp;&lt;A href="https://github.com/sasutils/macros/blob/master/varinfo.sas" target="_self"&gt;%VARINFO()&lt;/A&gt;&amp;nbsp; macro to detect the type of the variable and then use it to determine whether or not you need to take action.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
%if %varinfo(HAVE,DATETIME,TYPE)=C %then %do;
    ... logic to generate ACTUAL_DATETIME ...
    rename actual_datetime=DateTime ;
    drop DateTime;
%end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You might also want to look into using a different file format for the transfer.&lt;/P&gt;
&lt;P&gt;Perhaps SAS transport files?&amp;nbsp; That way there is no conversion to be done.&lt;/P&gt;
&lt;P&gt;Or a delimited text file.&amp;nbsp; &amp;nbsp;That way you can write a data step to read the file and set the variable names, types and lengths they way you want them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Apr 2026 18:54:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-Data-from-Excel-DateTime-column-has-mixed-values/m-p/986045#M379897</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2026-04-06T18:54:28Z</dc:date>
    </item>
    <item>
      <title>Re: Import Data from Excel - DateTime column has mixed values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Import-Data-from-Excel-DateTime-column-has-mixed-values/m-p/986052#M379898</link>
      <description>&lt;P&gt;Using File - Save as in Excel with CSV as target does&amp;nbsp;&lt;STRONG&gt;NOT&lt;/STRONG&gt; modify the source file in any way.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Apr 2026 19:23:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Import-Data-from-Excel-DateTime-column-has-mixed-values/m-p/986052#M379898</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2026-04-06T19:23:07Z</dc:date>
    </item>
  </channel>
</rss>

