<?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: Read in alphanumeric timestamp values (26 characters long) with suitable informat in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Read-in-alphanumeric-timestamp-values-26-characters-long-with/m-p/779573#M248310</link>
    <description>&lt;P&gt;You can convert it into a datetime value (number of seconds since 1960) using the YMDDTTM informat.&lt;/P&gt;
&lt;P&gt;But you cannot store the full 6 digits of the fractional seconds exactly.&amp;nbsp; The floating point numbers that SAS uses to store numbers only support about 15 decimal digits so the latest date that can be exactly represented as datetime with 6 decimal places is in 1988.&amp;nbsp; Plus you cannot represent decimal fraction exactly in floating point binary anyway.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;544   data test;
545     ts_char= "2021-10-17-20.00.05.571907";
546     ts = input(ts_char, ymddttm26.);
547     maxint=constant('exactint')/10E6;
548     put ts_char= /(ts maxint) (=comma32.6)/ (ts maxint)(=datetime25.6);
549   run;

ts_char=2021-10-17-20.00.05.571907
ts=1,950,120,005.571900 maxint=900,719,925.474099
ts=17OCT2021:20:00:05.571907 maxint=16JUL1988:23:58:45.474099
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 10 Nov 2021 14:52:39 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2021-11-10T14:52:39Z</dc:date>
    <item>
      <title>Read in alphanumeric timestamp values (26 characters long) with suitable informat</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-in-alphanumeric-timestamp-values-26-characters-long-with/m-p/779532#M248286</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;&lt;P&gt;is there a suitable SAS timestamp INFORMAT, which can process a 26 character long timestamp value &lt;EM&gt;which includes 6 decimal places&lt;/EM&gt;?&lt;/P&gt;&lt;P&gt;I only found the&amp;nbsp;&lt;A href="https://support.sas.com/documentation/cdl/en/leforinforref/64790/HTML/default/viewer.htm#p1hsn1ji141r4zn0z3xm2dthop6a.htm" target="_self"&gt;ANYDTDTM&lt;/A&gt;&amp;nbsp;INFORMAT. But using this informat, the six decimal places are truncated and set to zero.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data have; 
length ts_alphanumeric $26.;
ts_alphanumeric = "2021-10-17-20.00.05.571907";
ts_notyet = input(ts_alphanumeric, ANYDTDTM.);
format ts_notyet datetime25.6;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;What I want, is this:&lt;/P&gt;&lt;PRE&gt;data want;&lt;BR /&gt;ts_want = dhms("17OCT2021"d, 20,00,05.571907) ;&lt;BR /&gt;format ts_want datetime25.6;&lt;BR /&gt;run;&lt;/PRE&gt;&lt;P&gt;I'd prefer an informat rather than use dateime functions like "dhms", "datepart", etc.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;FK1&lt;/P&gt;</description>
      <pubDate>Wed, 10 Nov 2021 11:01:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-in-alphanumeric-timestamp-values-26-characters-long-with/m-p/779532#M248286</guid>
      <dc:creator>FK1</dc:creator>
      <dc:date>2021-11-10T11:01:40Z</dc:date>
    </item>
    <item>
      <title>Re: Read in alphanumeric timestamp values (26 characters long) with suitable informat</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-in-alphanumeric-timestamp-values-26-characters-long-with/m-p/779557#M248298</link>
      <description>&lt;P&gt;I think you can use the&amp;nbsp;&lt;SPAN&gt;ymddttm26. informat - it is important to use the length also, as the informat will otherwise stop reading after the last decimal point.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Nov 2021 14:03:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-in-alphanumeric-timestamp-values-26-characters-long-with/m-p/779557#M248298</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2021-11-10T14:03:34Z</dc:date>
    </item>
    <item>
      <title>Re: Read in alphanumeric timestamp values (26 characters long) with suitable informat</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-in-alphanumeric-timestamp-values-26-characters-long-with/m-p/779563#M248302</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/76464"&gt;@s_lassen&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I think you can use the&amp;nbsp;&lt;SPAN&gt;ymddttm26. informat - it is important to use the length also, as the informat will otherwise stop reading after the last decimal point.&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes YMDDTTM works with wacky delimiters&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_; 
   length ts_alphanumeric $26;
   do ts_alphanumeric = "2021-10-17-20.00.05.571907","2021-10-17T20:00:05.571907";
      ts_notyet = input(ts_alphanumeric, E8601DT26.);
      put _all_;
      ts_notyet = input(ts_alphanumeric, ymddttm26.);
      put _all_;
      ts_notyet = input(ts_alphanumeric, ANYDTDTM26.);
      format ts_notyet datetime25.6;
      put _all_;
      end;
   run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Nov 2021 14:28:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-in-alphanumeric-timestamp-values-26-characters-long-with/m-p/779563#M248302</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2021-11-10T14:28:48Z</dc:date>
    </item>
    <item>
      <title>Re: Read in alphanumeric timestamp values (26 characters long) with suitable informat</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-in-alphanumeric-timestamp-values-26-characters-long-with/m-p/779573#M248310</link>
      <description>&lt;P&gt;You can convert it into a datetime value (number of seconds since 1960) using the YMDDTTM informat.&lt;/P&gt;
&lt;P&gt;But you cannot store the full 6 digits of the fractional seconds exactly.&amp;nbsp; The floating point numbers that SAS uses to store numbers only support about 15 decimal digits so the latest date that can be exactly represented as datetime with 6 decimal places is in 1988.&amp;nbsp; Plus you cannot represent decimal fraction exactly in floating point binary anyway.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;544   data test;
545     ts_char= "2021-10-17-20.00.05.571907";
546     ts = input(ts_char, ymddttm26.);
547     maxint=constant('exactint')/10E6;
548     put ts_char= /(ts maxint) (=comma32.6)/ (ts maxint)(=datetime25.6);
549   run;

ts_char=2021-10-17-20.00.05.571907
ts=1,950,120,005.571900 maxint=900,719,925.474099
ts=17OCT2021:20:00:05.571907 maxint=16JUL1988:23:58:45.474099
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Nov 2021 14:52:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-in-alphanumeric-timestamp-values-26-characters-long-with/m-p/779573#M248310</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-11-10T14:52:39Z</dc:date>
    </item>
    <item>
      <title>Re: Read in alphanumeric timestamp values (26 characters long) with suitable informat</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-in-alphanumeric-timestamp-values-26-characters-long-with/m-p/779793#M248407</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;But you cannot store the full 6 digits of the fractional seconds exactly.&amp;nbsp; The floating point numbers that SAS uses to store numbers only support about 15 decimal digits so the latest date that can be exactly represented as datetime with 6 decimal places is in 1988.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This is an interesting consideration. There are indeed datetime values whose internal representation under Windows or Unix does not change if one microsecond is added, i.e., where the precision of 52 mantissa bits is insufficient. An example, &lt;FONT face="courier new,courier"&gt;31DEC9999:23:59:59.999999&lt;/FONT&gt;, was discussed in an &lt;A href="https://communities.sas.com/t5/SAS-Programming/Odd-decimal-behaviour-precission-error/m-p/744766" target="_blank" rel="noopener"&gt;earlier thread&lt;/A&gt; started by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/114220"&gt;@FK1&lt;/a&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In theory I think the precision should be sufficient for storing datetime values (including microseconds) with an absolute value less than &lt;FONT face="courier new,courier"&gt;2**33='15MAR&lt;STRONG&gt;2232&lt;/STRONG&gt;:12:56:32'dt&lt;/FONT&gt;&amp;nbsp;(and I haven't found a counterexample yet). Reason: The least significant bit, i.e., the 52nd mantissa bit of such values has a place value &lt;FONT face="courier new,courier"&gt;&amp;lt;=2**(32-52)=2**-20&amp;lt;1E-6&lt;/FONT&gt;. So the numeric representation error will be &lt;FONT face="courier new,courier"&gt;&amp;lt;0.5E-6&lt;/FONT&gt;, hence small enough so that rounding the corresponding decimal value to millionths should return the original value. Of course, &lt;EM&gt;calculations&lt;/EM&gt; involving such values may require a greater precision.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In a few tests (with Windows SAS 9.4M5) I made some surprising observations, though:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;About 0.004% of a random sample of 10 million datetimes &lt;FONT face="courier new,courier"&gt;dt&lt;/FONT&gt; with (up to) six decimals in the date range 1 Jan 1900 - 14 Mar 2232 did &lt;EM&gt;not&lt;/EM&gt; satisfy the equation&amp;nbsp;&lt;FONT face="courier new,courier"&gt;dt = input(put(dt,datetime25.6),datetime25.)&lt;/FONT&gt;. But the differences were &lt;FONT face="courier new,courier"&gt;&amp;lt;=2**-24&amp;lt;6E-8&lt;/FONT&gt;, all examples were datetimes from years 1943-1976, most of them even from 1959 and 1960, i.e., with &lt;EM&gt;small&lt;/EM&gt; absolute values. Example: &lt;FONT face="courier new,courier"&gt;dt=66.544784&lt;/FONT&gt;.&lt;BR /&gt;
&lt;PRE&gt;66+544784/1e6 &lt;STRONG&gt;eq&lt;/STRONG&gt; 66.544784 &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;ne&lt;/STRONG&gt;&lt;/FONT&gt; '01JAN1960:00:01:06.544784'dt &lt;STRONG&gt;eq&lt;/STRONG&gt; input('01JAN1960:00:01:06.544784',datetime25.)&lt;/PRE&gt;
It appears that writing a datetime as a &lt;FONT face="courier new,courier"&gt;'...'dt&lt;/FONT&gt; literal or reading the corresponding string with the DATETIME25. informat occasionally leads to a slightly less accurate internal binary representation than writing it as a number or calculating it from integers -- yet without affecting the decimal value rounded to millionths.&lt;BR /&gt;&lt;BR /&gt;&lt;/LI&gt;
&lt;LI&gt;About 0.1% of the random sample described above showed a different fractional part when displayed in E8601DT26.6 format than in DATETIME25.6 format. All these cases were &lt;EM&gt;negative&lt;/EM&gt; datetimes from the years 1936-1951. Example:&amp;nbsp;&lt;FONT face="courier new,courier"&gt;dt='04MAY1951:13:01:56.3852'dt (=-273322683.6148)&lt;/FONT&gt;.&lt;BR /&gt;
&lt;PRE&gt;put(dt,datetime25.6)= '04MAY1951:13:01:56.385200'
put(dt,e8601dt26.6) ='1951-05-04T13:01:56.38520&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/FONT&gt;'&lt;/PRE&gt;
After correction of the decimals (if needed), reading the E8601DT26.6 representations with the YMDDTTM26. informat resulted in the same values as reading the corresponding DATETIME25.6 representations with the DATETIME25. informat.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Nov 2021 13:39:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-in-alphanumeric-timestamp-values-26-characters-long-with/m-p/779793#M248407</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-11-11T13:39:36Z</dc:date>
    </item>
    <item>
      <title>Re: Read in alphanumeric timestamp values (26 characters long) with suitable informat</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-in-alphanumeric-timestamp-values-26-characters-long-with/m-p/779797#M248411</link>
      <description>&lt;P&gt;Thanks for that detailed investigation.&lt;/P&gt;
&lt;P&gt;I think that I have seen before that there is also some slight differences in the conversion of done for numeric literals in a program and the result of reading the same string with the INPUT statement (or INPUT()&amp;nbsp; function).&amp;nbsp; Something about the difference in the number of bits uses in the process of converting the strings into binary numbers.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Nov 2021 14:00:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-in-alphanumeric-timestamp-values-26-characters-long-with/m-p/779797#M248411</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-11-11T14:00:07Z</dc:date>
    </item>
    <item>
      <title>Re: Read in alphanumeric timestamp values (26 characters long) with suitable informat</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Read-in-alphanumeric-timestamp-values-26-characters-long-with/m-p/779799#M248413</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But you cannot store the full 6 digits of the fractional seconds exactly.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Unless your SAS runs on z/OS on a zSeries, where you have four more bits in the mantissa.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Nov 2021 14:05:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Read-in-alphanumeric-timestamp-values-26-characters-long-with/m-p/779799#M248413</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-11-11T14:05:21Z</dc:date>
    </item>
  </channel>
</rss>

