<?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: Convert ISO8601 datetime string into SAS datetime value in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Convert-ISO8601-datetime-string-into-SAS-datetime-value/m-p/560220#M156595</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/6183"&gt;@CurtisER&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think you just missed the colon in the offset: ...-04&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;:&lt;/STRONG&gt;&lt;/FONT&gt;00.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data x;
x = '2019-05-17T10:42:28.697604000-04:00';
y = input(x, e8601dz35.);
format y datetime20.;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Why, yes, I believe I did miss the colon in the offset!&amp;nbsp; Thanks for catching something this trivial,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;.&lt;/P&gt;</description>
    <pubDate>Mon, 20 May 2019 16:43:32 GMT</pubDate>
    <dc:creator>CurtisER</dc:creator>
    <dc:date>2019-05-20T16:43:32Z</dc:date>
    <item>
      <title>Convert ISO8601 datetime string into SAS datetime value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-ISO8601-datetime-string-into-SAS-datetime-value/m-p/560213#M156591</link>
      <description>&lt;P&gt;I am referencing to a previous article in this &lt;A title="Convert ISO8601 string to datetime format" href="https://communities.sas.com/t5/General-SAS-Programming/Convert-ISO8601-string-to-datetime-format/m-p/421077#M52603" target="_blank" rel="noopener"&gt;link&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to extract the modification datetime by using the Linux command &lt;FONT face="courier new,courier"&gt;stat&lt;/FONT&gt;.&amp;nbsp; Then, I convert it into ISO8601 format which then I convert it into SAS datetime value.&amp;nbsp; However, it does not appear to be working properly for me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The stat command is issued as &lt;FONT face="courier new,courier"&gt;stat -c '%n %y' *&lt;/FONT&gt;.&lt;/P&gt;&lt;P&gt;The result is returned as:&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;copy_other_v2.sas 2019-05-17 10:42:28.697604000 -0400&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;copy_pgms_driver_21_cer.sas 2019-05-17 10:13:07.435587000 -0400 &lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, it's got blanks and missing the 'T' in the above DT string.&amp;nbsp; For the filename 'copy_other_v2.sas', I recoded them by adding a 'T' before the datetime part and removed the blank in the timezone offset.&amp;nbsp; So, the ISO8601 should look like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;2019-05-17T10:42:28.697604000-0400&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Right?&amp;nbsp; Then, since the length is 34, I tried to convert that string into SAS DT value using the E8601DZ34.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*
ersaces01:/aepp/users/reidc/copyjobs$ stat -c '%n %y' *

copy_other_v2.sas 2019-05-17 10:42:28.697604000 -0400
copy_pgms_driver_21_cer.sas 2019-05-17 10:13:07.435587000 -0400
*/

/* Documentation used for this test:
   https://documentation.sas.com/?docsetId=leforinforref&amp;amp;docsetTarget=p1a0qt18rxydrkn1b0rtdfh2t8zs.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en
   SAS Communities article referenced:
   https://communities.sas.com/t5/General-SAS-Programming/Convert-ISO8601-string-to-datetime-format/m-p/421077#M52603
*/

data x;
   /* Recode original DT value into IS08601 DT    */
   /*   2019-05-17 10:42:28.697604000 -0400 becomes */
   /*   2019-05-17T10:42:28.697604000-0400          */
   x = '2019-05-17T10:42:28.697604000-0400';

   lenx = length(x);
   put lenx=;

   y = input(x, e8601dz34.);
   put y=;

   format y datetime20.;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the error I kept getting:&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;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;241  /*
242  ersaces01:/aepp/users/reidc/copyjobs$ stat -c '%n %y' *
243
244  copy_other_v2.sas 2019-05-17 10:42:28.697604000 -0400
245  copy_pgms_driver_21_cer.sas 2019-05-17 10:13:07.435587000 -0400
246  */
247
248  /* Documentation used for this test:
249     https://documentation.sas.com/?docsetId=leforinforref&amp;amp;docsetTarget=p1a0qt18rxydrkn
249! 1b0rtdfh2t8zs.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en
250     SAS Communities article referenced:
251     https://communities.sas.com/t5/General-SAS-Programming/Convert-ISO8601-string-to-d
251! atetime-format/m-p/421077#M52603
252  */
253
254  data x;
255     /* Recode original DT value into IS08601 DT    */
256     /*   2019-05-17 10:42:28.697604000 -0400 becomes */
257     /*   2019-05-17T10:42:28.697604000-0400          */
258     x = '2019-05-17T10:42:28.697604000-0400';
259
260     lenx = length(x);
261     put lenx=;
262
263     y = input(x, e8601dz34.);
264     put y=;
265
266     format y datetime20.;
267  run;

lenx=34
NOTE: Invalid argument to function INPUT at line 263 column 8.
y=.
x=2019-05-17T10:42:28.697604000-0400 lenx=34 y=. _ERROR_=1 _N_=1
NOTE: Mathematical operations could not be performed at the following places. The results
      of the operations have been set to missing values.
      Each place is given by: (Number of times) at (Line):(Column).
      1 at 263:8
NOTE: The data set WORK.X has 1 observations and 3 variables.
NOTE: DATA statement used (Total process time):
      real time           0.02 seconds
      cpu time            0.03 seconds&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I expected the value of y to be in a numeric DT value formatted DATETIME20.&amp;nbsp; Can someone help me with this issue?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 May 2019 16:22:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-ISO8601-datetime-string-into-SAS-datetime-value/m-p/560213#M156591</guid>
      <dc:creator>CurtisER</dc:creator>
      <dc:date>2019-05-20T16:22:39Z</dc:date>
    </item>
    <item>
      <title>Re: Convert ISO8601 datetime string into SAS datetime value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-ISO8601-datetime-string-into-SAS-datetime-value/m-p/560217#M156593</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/6183"&gt;@CurtisER&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think you just missed the colon in the offset: ...-04&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;:&lt;/STRONG&gt;&lt;/FONT&gt;00.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data x;
x = '2019-05-17T10:42:28.697604000-04:00';
y = input(x, e8601dz35.);
format y datetime20.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 20 May 2019 16:34:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-ISO8601-datetime-string-into-SAS-datetime-value/m-p/560217#M156593</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-05-20T16:34:47Z</dc:date>
    </item>
    <item>
      <title>Re: Convert ISO8601 datetime string into SAS datetime value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-ISO8601-datetime-string-into-SAS-datetime-value/m-p/560220#M156595</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/6183"&gt;@CurtisER&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think you just missed the colon in the offset: ...-04&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;:&lt;/STRONG&gt;&lt;/FONT&gt;00.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data x;
x = '2019-05-17T10:42:28.697604000-04:00';
y = input(x, e8601dz35.);
format y datetime20.;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Why, yes, I believe I did miss the colon in the offset!&amp;nbsp; Thanks for catching something this trivial,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;.&lt;/P&gt;</description>
      <pubDate>Mon, 20 May 2019 16:43:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-ISO8601-datetime-string-into-SAS-datetime-value/m-p/560220#M156595</guid>
      <dc:creator>CurtisER</dc:creator>
      <dc:date>2019-05-20T16:43:32Z</dc:date>
    </item>
  </channel>
</rss>

