<?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: Numeric to Date Conversion in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Numeric-to-Date-Conversion/m-p/738884#M230541</link>
    <description>&lt;P&gt;DATA raw;&lt;/P&gt;&lt;P&gt;&amp;nbsp; SET raw;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; FORMAT LastAccessTimeStamp datetime16.;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;RUN;;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 04 May 2021 12:48:40 GMT</pubDate>
    <dc:creator>jonas_bilenas</dc:creator>
    <dc:date>2021-05-04T12:48:40Z</dc:date>
    <item>
      <title>Numeric to Date Conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numeric-to-Date-Conversion/m-p/738874#M230536</link>
      <description>&lt;P&gt;I have a .xlsx file that has this column:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;LastAccessTimeStamp&lt;/STRONG&gt;&lt;BR /&gt;3/23/2021 14:15&lt;BR /&gt;44278.89847&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I do proc import, the output was this:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;LastAccessTimeStamp&lt;/STRONG&gt;&lt;BR /&gt;44278.59403&lt;BR /&gt;44278.89847&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;May I know what should be done to convert it from numeric to date with format datetime16. ?&lt;/P&gt;</description>
      <pubDate>Tue, 04 May 2021 12:34:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numeric-to-Date-Conversion/m-p/738874#M230536</guid>
      <dc:creator>iSAS</dc:creator>
      <dc:date>2021-05-04T12:34:17Z</dc:date>
    </item>
    <item>
      <title>Re: Numeric to Date Conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numeric-to-Date-Conversion/m-p/738876#M230537</link>
      <description>&lt;P&gt;In a DATA step, or in PROC DATASETS, assign the datetime16. format to this variable.&lt;/P&gt;</description>
      <pubDate>Tue, 04 May 2021 12:36:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numeric-to-Date-Conversion/m-p/738876#M230537</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-05-04T12:36:17Z</dc:date>
    </item>
    <item>
      <title>Re: Numeric to Date Conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numeric-to-Date-Conversion/m-p/738878#M230538</link>
      <description>I did this after the proc import but it didn't work:&lt;BR /&gt;Data raw1;&lt;BR /&gt;Set raw (rename=(LastAccessTimeStamp=LastAccessTimeStamp1));&lt;BR /&gt;LastAccessTimeStamp=input(put(LastAccessTimeStamp1,8.6),datetime16.);&lt;BR /&gt;run;</description>
      <pubDate>Tue, 04 May 2021 12:39:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numeric-to-Date-Conversion/m-p/738878#M230538</guid>
      <dc:creator>iSAS</dc:creator>
      <dc:date>2021-05-04T12:39:04Z</dc:date>
    </item>
    <item>
      <title>Re: Numeric to Date Conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numeric-to-Date-Conversion/m-p/738880#M230539</link>
      <description>&lt;P&gt;You want to assign a format to the variable. INPUT(PUT()) doesn't seem like it should work, to me.&lt;/P&gt;</description>
      <pubDate>Tue, 04 May 2021 12:40:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numeric-to-Date-Conversion/m-p/738880#M230539</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-05-04T12:40:33Z</dc:date>
    </item>
    <item>
      <title>Re: Numeric to Date Conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numeric-to-Date-Conversion/m-p/738883#M230540</link>
      <description>I also did this after the proc import but all the values just turned into 01JAN60:hh:mm:ss&lt;BR /&gt;Data raw1;&lt;BR /&gt;Set raw;&lt;BR /&gt;format LastAccessTimeStamp datetime16.;&lt;BR /&gt;run;</description>
      <pubDate>Tue, 04 May 2021 12:45:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numeric-to-Date-Conversion/m-p/738883#M230540</guid>
      <dc:creator>iSAS</dc:creator>
      <dc:date>2021-05-04T12:45:46Z</dc:date>
    </item>
    <item>
      <title>Re: Numeric to Date Conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numeric-to-Date-Conversion/m-p/738884#M230541</link>
      <description>&lt;P&gt;DATA raw;&lt;/P&gt;&lt;P&gt;&amp;nbsp; SET raw;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; FORMAT LastAccessTimeStamp datetime16.;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;RUN;;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 04 May 2021 12:48:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numeric-to-Date-Conversion/m-p/738884#M230541</guid>
      <dc:creator>jonas_bilenas</dc:creator>
      <dc:date>2021-05-04T12:48:40Z</dc:date>
    </item>
    <item>
      <title>Re: Numeric to Date Conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numeric-to-Date-Conversion/m-p/738886#M230542</link>
      <description>&lt;P&gt;These are neither SAS date values nor SAS datetime values. So you will have to do the conversion and then assign the proper formats.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data raw1;
    set raw;
    time=(lastaccesstimestamp-floor(lastaccesstimestamp))*24*60*60; /* Convert decimal part of the date into seconds */
    date=floor(lastaccesstimestamp)-21916; /* Convert Excel date to SAS date */
    format date date9. time time.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 May 2021 12:58:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numeric-to-Date-Conversion/m-p/738886#M230542</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-05-04T12:58:22Z</dc:date>
    </item>
    <item>
      <title>Re: Numeric to Date Conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Numeric-to-Date-Conversion/m-p/738889#M230544</link>
      <description>&lt;P&gt;So it looks like you are trying to say the cells in the XLSX file for that column have numbers like&amp;nbsp;&lt;SPAN&gt;44,278.89847 that when displayed using one of Excel's datetiime formats looks like the string '3/23/2021 14:15'.&amp;nbsp; Excel stores datetime values as the number of days and fractions of a day since 1900.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;If all of the cells in that column had values like that then SAS would have created a numeric value with datetime values converted to the SAS equivalent number of seconds since 1960.&amp;nbsp; If it did that then the values would NOT look like&amp;nbsp;44278.89847.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;So I assume that what happened is that one or more cells in that column contained a character string. So SAS defined&amp;nbsp;LastAccessTimeStamp as a character variable and stored the numbers as a digit string that represents that number.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;To fix that convert the string to a number, adjust for difference in starting day between the two systems, and convert the days + fraction of day into seconds.&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  format real_LastAccessTimeStamp datetime20. ;
  real_LastAccessTimeStamp= dhms(input(LastAccessTimeStamp,32.)+'30DEC1899'd,0,0,0);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 04 May 2021 12:59:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Numeric-to-Date-Conversion/m-p/738889#M230544</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-05-04T12:59:51Z</dc:date>
    </item>
  </channel>
</rss>

