<?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: format datetime handles lengths strangely in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/format-datetime-handles-lengths-strangely/m-p/649253#M194615</link>
    <description>&lt;P&gt;Previous post from 2017&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Number-of-digits-for-year-when-using-datetime18-format/td-p/341192" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/Number-of-digits-for-year-when-using-datetime18-format/td-p/341192&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 20 May 2020 15:01:39 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2020-05-20T15:01:39Z</dc:date>
    <item>
      <title>format datetime handles lengths strangely</title>
      <link>https://communities.sas.com/t5/SAS-Programming/format-datetime-handles-lengths-strangely/m-p/649058#M194541</link>
      <description>&lt;P&gt;The requested length is not used by format datetime. This:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data T1;
  A=put(datetime(),datetime20. -l); L=length(A); putlog '20 ' L A ;  
  A=put(datetime(),datetime19. -l); L=length(A); putlog '19 ' L A ; 
  A=put(datetime(),datetime18. -l); L=length(A); putlog '18 ' L A ; 
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;yields:&lt;/P&gt;
&lt;PRE&gt;20 18 20MAY2020:11:08:13
19 18 20MAY2020:11:08:13
18 16 20MAY20:11:08:13
&lt;/PRE&gt;
&lt;P&gt;The length created is always smaller than the length requested, and includes left padding.&lt;/P&gt;
&lt;P&gt;This means that one must use a different format/informat for writing and then reading a date:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename TMP temp;
       
data _null_; 
  file TMP ;
  STR=catx(',','*',put(datetime(),datetime20. -l),'*');
  put STR;
run;

data T2; 
  infile TMP dlm=',';
  input A $ B datetime18. C $;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The value is written with a length of 20 but must be read with an informat length of 18.&lt;/P&gt;
&lt;P&gt;Writing with a length of 18 would mandate reading 16 characters.&lt;/P&gt;
&lt;P&gt;And comments on this peculiar behaviour?&lt;/P&gt;</description>
      <pubDate>Wed, 20 May 2020 00:13:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/format-datetime-handles-lengths-strangely/m-p/649058#M194541</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-05-20T00:13:42Z</dc:date>
    </item>
    <item>
      <title>Re: format datetime handles lengths strangely</title>
      <link>https://communities.sas.com/t5/SAS-Programming/format-datetime-handles-lengths-strangely/m-p/649061#M194544</link>
      <description>&lt;P&gt;Known bug. Been there as long as I can remember.&lt;/P&gt;
&lt;P&gt;I am not too worried about the extra space, but the fact that it cannot generate 4 digit years when you ask for width of 18 is the one that causes confusion.&amp;nbsp; 9 characters for DATE9. plus 8 characters for TIME8. plus a colon separator should fit into 18 characters.&lt;/P&gt;</description>
      <pubDate>Wed, 20 May 2020 00:22:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/format-datetime-handles-lengths-strangely/m-p/649061#M194544</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-05-20T00:22:36Z</dc:date>
    </item>
    <item>
      <title>Re: format datetime handles lengths strangely</title>
      <link>https://communities.sas.com/t5/SAS-Programming/format-datetime-handles-lengths-strangely/m-p/649102#M194566</link>
      <description>&lt;P&gt;Thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;. I've always forced a length of 20 to overcome a behaviour I knew was inconsistent with other formats. I just delved now into the details.&lt;/P&gt;
&lt;P&gt;I'll ask tech support to explain the outputs, and to create a Usage Note if none exists. There's probably no way this will be corrected.&lt;/P&gt;</description>
      <pubDate>Wed, 20 May 2020 06:53:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/format-datetime-handles-lengths-strangely/m-p/649102#M194566</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-05-20T06:53:37Z</dc:date>
    </item>
    <item>
      <title>Re: format datetime handles lengths strangely</title>
      <link>https://communities.sas.com/t5/SAS-Programming/format-datetime-handles-lengths-strangely/m-p/649227#M194609</link>
      <description>&lt;P&gt;The online documentation examples of datetimew.d clearly show that behavior for datetime18. where the examples use default 16, 7, 12, 18, 18.1 19, 20.1 and 21.2&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Personally I blame this on pre-Y2K mindsets for setting that behavior with 2 leading spaces instead of the 4 digit year.&lt;/P&gt;</description>
      <pubDate>Wed, 20 May 2020 14:05:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/format-datetime-handles-lengths-strangely/m-p/649227#M194609</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-05-20T14:05:03Z</dc:date>
    </item>
    <item>
      <title>Re: format datetime handles lengths strangely</title>
      <link>https://communities.sas.com/t5/SAS-Programming/format-datetime-handles-lengths-strangely/m-p/649253#M194615</link>
      <description>&lt;P&gt;Previous post from 2017&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Number-of-digits-for-year-when-using-datetime18-format/td-p/341192" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/Number-of-digits-for-year-when-using-datetime18-format/td-p/341192&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 May 2020 15:01:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/format-datetime-handles-lengths-strangely/m-p/649253#M194615</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-05-20T15:01:39Z</dc:date>
    </item>
    <item>
      <title>Re: format datetime handles lengths strangely</title>
      <link>https://communities.sas.com/t5/SAS-Programming/format-datetime-handles-lengths-strangely/m-p/649386#M194672</link>
      <description>&lt;P&gt;Thanks guys.&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&amp;gt; Personally I blame this on pre-Y2K mindsets for setting that behavior with 2 leading spaces instead of the 4 digit year&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;That could be an explanation.&lt;/P&gt;
&lt;P&gt;From the documentation, it seems the concern may have been to leave space for the decimal dot and the first &lt;EM&gt;seconds&lt;/EM&gt; digit. Why just the first digit? That's weird.&lt;/P&gt;
&lt;P&gt;Afaik, no other format does this: systematically use less space than it is allowed (unless decimals are requested).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Storm in a tea cup then. Thanks again for taking the time to reply.&amp;nbsp;&lt;/P&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 May 2020 21:14:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/format-datetime-handles-lengths-strangely/m-p/649386#M194672</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-05-20T21:14:22Z</dc:date>
    </item>
  </channel>
</rss>

