<?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: Informat for 'yyyy-mm-dd hh:mm:ss UTC'? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Informat-for-yyyy-mm-dd-hh-mm-ss-UTC/m-p/815469#M321880</link>
    <description>Ahh, yes, typos rear their ugly head again.  Thanks for this solution.  I'm marking it as Accepted.</description>
    <pubDate>Fri, 27 May 2022 18:57:24 GMT</pubDate>
    <dc:creator>genemroz</dc:creator>
    <dc:date>2022-05-27T18:57:24Z</dc:date>
    <item>
      <title>Informat for 'yyyy-mm-dd hh:mm:ss UTC'?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Informat-for-yyyy-mm-dd-hh-mm-ss-UTC/m-p/815446#M321873</link>
      <description>&lt;P&gt;Esteemed Advisers;&lt;/P&gt;
&lt;P&gt;I'm trying to import a csv file with datetime data in the following format:&lt;/P&gt;
&lt;P&gt;yyyy-mm-dd hh:mm:ss UTC&lt;/P&gt;
&lt;P&gt;I can't find an informat that works and need some advice on how to proceed.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below is a sample of what I've tried but isn't working--(thanks in advance!):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; data have;
 /*INFORMAT*/
 informat created_at $19.;
 /*FORMAT*/
 format created_UTC datetime16. ;
 /**/
 input
 created_at
 ;
 datalines;
 2022-04-01 00:01:20 UTC
 2022-04-01 00:03:20 UTC
 2022-04-01 00:05:20 UTC
 run;
 
data want
created_UTC
01APR22:00:01:20
01APR22:00:03:20
01APR22:00:04:20&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 27 May 2022 17:45:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Informat-for-yyyy-mm-dd-hh-mm-ss-UTC/m-p/815446#M321873</guid>
      <dc:creator>genemroz</dc:creator>
      <dc:date>2022-05-27T17:45:11Z</dc:date>
    </item>
    <item>
      <title>Re: Informat for 'yyyy-mm-dd hh:mm:ss UTC'?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Informat-for-yyyy-mm-dd-hh-mm-ss-UTC/m-p/815447#M321874</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
format created_at datetime21. ;
input
 created_at ANYDTDTM19.
;
datalines;
2022-04-01 00:01:20 UTC
2022-04-01 00:03:20 UTC
2022-04-01 00:05:20 UTC
run;
proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 27 May 2022 17:54:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Informat-for-yyyy-mm-dd-hh-mm-ss-UTC/m-p/815447#M321874</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2022-05-27T17:54:53Z</dc:date>
    </item>
    <item>
      <title>Re: Informat for 'yyyy-mm-dd hh:mm:ss UTC'?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Informat-for-yyyy-mm-dd-hh-mm-ss-UTC/m-p/815451#M321875</link>
      <description>&lt;P&gt;You cannot use a numeric format with a character variable.&amp;nbsp; In particular to use the DATETIME format to display a variable it needs to be a numeric variable with datetime values (number of seconds since 1960).&lt;/P&gt;
&lt;P&gt;So if you have this data:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input created_at $23.;
datalines;
2022-04-01 00:01:20 UTC
2022-04-01 00:03:20 UTC
2022-04-01 00:05:20 UTC
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can try to convert it to a datetime value by ignoring the timezone.&amp;nbsp; You could then use the TZONEOFF() function to try to adjust to a different timezone if you want.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  dt = input(created_at,anydtdtm19.);
  timezone = scan(created_at,-1,' ');
  offset = tzoneoff(timezone);
  local_offset = tzoneoff();
  local_dt = dt - offset + local_offset;
  format dt local_dt datetime19. offset local_offset time6.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1653674746994.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/71820iB5BB5D432AF2835D/image-size/large?v=v2&amp;amp;px=999" role="button" title="Tom_0-1653674746994.png" alt="Tom_0-1653674746994.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 27 May 2022 18:05:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Informat-for-yyyy-mm-dd-hh-mm-ss-UTC/m-p/815451#M321875</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-05-27T18:05:58Z</dc:date>
    </item>
    <item>
      <title>Re: Informat for 'yyyy-mm-dd hh:mm:ss UTC'?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Informat-for-yyyy-mm-dd-hh-mm-ss-UTC/m-p/815466#M321878</link>
      <description>&lt;P&gt;Tom:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for the quick response.&amp;nbsp; I tried your code but am not getting the result that you show.&amp;nbsp; Namely, the dt and local_dt variable columns are empty.&amp;nbsp; My code is below:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input created_at $23.;
datalines;
2022-04-01 00:01:20 UTC
2022-04-01 00:03:20 UTC
2022-04-01 00:05:20 UTC
run;

data want;
set have;
dt=input(created_at,anytdtdtm19.);
timezone=scan(created_at,-1,' ');
offset=tzoneoff(timezone); 
local_offset=tzoneoff();
local_dt=dt - offset + local_offset;
format dt local_dt datetime19. offset local_offset time6.;
run;
proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 27 May 2022 18:50:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Informat-for-yyyy-mm-dd-hh-mm-ss-UTC/m-p/815466#M321878</guid>
      <dc:creator>genemroz</dc:creator>
      <dc:date>2022-05-27T18:50:54Z</dc:date>
    </item>
    <item>
      <title>Re: Informat for 'yyyy-mm-dd hh:mm:ss UTC'?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Informat-for-yyyy-mm-dd-hh-mm-ss-UTC/m-p/815467#M321879</link>
      <description>&lt;P&gt;An extra T got inserted into the informat name in the INPUT() function call.&lt;/P&gt;
&lt;PRE&gt;1421  set have;
1422  dt=input(created_at,anytdtdtm19.);
                          ------------
                          48
ERROR 48-59: The informat ANYTDTDTM was not found or could not be loaded.

&lt;/PRE&gt;
&lt;P&gt;ANYDTDTM is the name of the informat.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the extra T is not in your code then change that the spaces in CREATED_AT are actually spaces and not tabs ('09'x) or non-breaking spaces ('A0'x) or some other invisible character.&lt;/P&gt;</description>
      <pubDate>Fri, 27 May 2022 18:55:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Informat-for-yyyy-mm-dd-hh-mm-ss-UTC/m-p/815467#M321879</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-05-27T18:55:43Z</dc:date>
    </item>
    <item>
      <title>Re: Informat for 'yyyy-mm-dd hh:mm:ss UTC'?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Informat-for-yyyy-mm-dd-hh-mm-ss-UTC/m-p/815469#M321880</link>
      <description>Ahh, yes, typos rear their ugly head again.  Thanks for this solution.  I'm marking it as Accepted.</description>
      <pubDate>Fri, 27 May 2022 18:57:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Informat-for-yyyy-mm-dd-hh-mm-ss-UTC/m-p/815469#M321880</guid>
      <dc:creator>genemroz</dc:creator>
      <dc:date>2022-05-27T18:57:24Z</dc:date>
    </item>
  </channel>
</rss>

