<?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: Importing a datetime variable with format yyyy-mm-ddThh:mm:ss.fffffffff in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Importing-a-datetime-variable-with-format-yyyy-mm-ddThh-mm-ss/m-p/795078#M254990</link>
    <description>&lt;P&gt;yes, this is stock trading data and microsecond matters&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 08 Feb 2022 22:15:27 GMT</pubDate>
    <dc:creator>somebody</dc:creator>
    <dc:date>2022-02-08T22:15:27Z</dc:date>
    <item>
      <title>Importing a datetime variable with format yyyy-mm-ddThh:mm:ss.fffffffff</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-a-datetime-variable-with-format-yyyy-mm-ddThh-mm-ss/m-p/794896#M254911</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I have a csv data file that contains a datetime column with value like the title. Below is an example. I tried using PROC IMPORT and the Import Data option but the output is just the date, which is clearly not what I am after.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;2021-06-01T07:00:00.294210290-04&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;How can I import this column in a data step? I search online and run into this format but I still could not figure out how.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;A href="https://support.sas.com/documentation/cdl/en/leforinforref/64790/HTML/default/viewer.htm#n1xn55wyvuf9zin14s3ccylye2ck.htm" target="_blank"&gt;https://support.sas.com/documentation/cdl/en/leforinforref/64790/HTML/default/viewer.htm#n1xn55wyvuf9zin14s3ccylye2ck.htm&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;So far, this is what I have tried:&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; proc import datafile='F:\data2000.csv' out=class
               dbms=csv replace;
guessingrows=10000;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WORK.class   ;
	%let _EFIERR_ = 0; /* set the ERROR detection macro variable */
	infile 'F:\data2000.csv' delimiter = ',' MISSOVER DSD lrecl=32767 firstobs=2 ;
	  ....
	  informat Date_Time E8601DTw. ;
	  ...
	  
	  format Date_Time E8601DTw. ;
	 ...
	input
	          ...
	           Date_Time
	           ...
	;
	if _ERROR_ then call symputx('_EFIERR_',1);  /* set ERROR detection macro variable */
	run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 08 Feb 2022 00:17:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-a-datetime-variable-with-format-yyyy-mm-ddThh-mm-ss/m-p/794896#M254911</guid>
      <dc:creator>somebody</dc:creator>
      <dc:date>2022-02-08T00:17:11Z</dc:date>
    </item>
    <item>
      <title>Re: Importing a datetime variable with format yyyy-mm-ddThh:mm:ss.fffffffff</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-a-datetime-variable-with-format-yyyy-mm-ddThh-mm-ss/m-p/794909#M254918</link>
      <description>&lt;P&gt;That is not a style that SAS has an informat for.&amp;nbsp; It is very similar to the&amp;nbsp;&lt;SPAN&gt;E8601DZ, but that needs an actual TIME string after the + or -.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;You could read it as a string and the append :00 to the end and then use the&amp;nbsp;E8601DZ informat.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Example:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;143   data test;
144     string='2021-06-01T07:00:00.294210290-04';
145     len=length(string);
146     dt = input(cats(string,':00'),E8601DZ35.);
147     format dt datetime29.9;
148     put (_all_) (=/);
149   run;


string=2021-06-01T07:00:00.294210290-04
len=32
dt=01JUN2021:11:00:00.294210196
&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;Note there is no need to use PROC IMPORT to guess how to read a text file. Just write your own data step to read it.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Feb 2022 02:26:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-a-datetime-variable-with-format-yyyy-mm-ddThh-mm-ss/m-p/794909#M254918</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-02-08T02:26:05Z</dc:date>
    </item>
    <item>
      <title>Re: Importing a datetime variable with format yyyy-mm-ddThh:mm:ss.fffffffff</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-a-datetime-variable-with-format-yyyy-mm-ddThh-mm-ss/m-p/794961#M254953</link>
      <description>&lt;P&gt;thanks, I used a DATA step to import the date_time column as text and extract the date part. However, I cannot format the time part as time as it has some microseconds. Do you know how I could format the time part? my time variable looks like this I think the -04 is time zone, not sure how to adjust for it&lt;/P&gt;
&lt;PRE&gt;07:00:00.294210290-04&lt;/PRE&gt;</description>
      <pubDate>Tue, 08 Feb 2022 10:31:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-a-datetime-variable-with-format-yyyy-mm-ddThh-mm-ss/m-p/794961#M254953</guid>
      <dc:creator>somebody</dc:creator>
      <dc:date>2022-02-08T10:31:28Z</dc:date>
    </item>
    <item>
      <title>Re: Importing a datetime variable with format yyyy-mm-ddThh:mm:ss.fffffffff</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-a-datetime-variable-with-format-yyyy-mm-ddThh-mm-ss/m-p/794995#M254966</link>
      <description>&lt;P&gt;See how to extra the time from the datetime, and format it:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
string='2021-06-01T07:00:00.294210290-04';
dt = input(cats(string,':00'),E8601DZ35.);
timevar = timepart(dt);
format
  dt datetime29.9
  timevar time18.9
;
put (_all_) (=/);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You will note that the datetime value is not correct after the 6th decimal (microseconds), because if the limits of 64-bit floating point arithmetic.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Feb 2022 15:03:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-a-datetime-variable-with-format-yyyy-mm-ddThh-mm-ss/m-p/794995#M254966</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-02-08T15:03:00Z</dc:date>
    </item>
    <item>
      <title>Re: Importing a datetime variable with format yyyy-mm-ddThh:mm:ss.fffffffff</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-a-datetime-variable-with-format-yyyy-mm-ddThh-mm-ss/m-p/795011#M254968</link>
      <description>&lt;P&gt;Do you really need time to the billionth of a second???&lt;/P&gt;</description>
      <pubDate>Tue, 08 Feb 2022 16:00:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-a-datetime-variable-with-format-yyyy-mm-ddThh-mm-ss/m-p/795011#M254968</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-02-08T16:00:53Z</dc:date>
    </item>
    <item>
      <title>Re: Importing a datetime variable with format yyyy-mm-ddThh:mm:ss.fffffffff</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-a-datetime-variable-with-format-yyyy-mm-ddThh-mm-ss/m-p/795055#M254978</link>
      <description>&lt;P&gt;Parse it again into two parts.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  string='07:00:00.294210290-04';
  time = input(scan(string,1,'+-'),time20.);
  offset_hours = input(substr(string,length(string)-2),32.);
  format time tod19.9 ;
  put (_all_) (=/);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results&lt;/P&gt;
&lt;PRE&gt;string=07:00:00.294210290-04
time=07:00:00.294210290
offset_hours=-4
&lt;/PRE&gt;</description>
      <pubDate>Tue, 08 Feb 2022 19:13:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-a-datetime-variable-with-format-yyyy-mm-ddThh-mm-ss/m-p/795055#M254978</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-02-08T19:13:45Z</dc:date>
    </item>
    <item>
      <title>Re: Importing a datetime variable with format yyyy-mm-ddThh:mm:ss.fffffffff</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-a-datetime-variable-with-format-yyyy-mm-ddThh-mm-ss/m-p/795078#M254990</link>
      <description>&lt;P&gt;yes, this is stock trading data and microsecond matters&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Feb 2022 22:15:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-a-datetime-variable-with-format-yyyy-mm-ddThh-mm-ss/m-p/795078#M254990</guid>
      <dc:creator>somebody</dc:creator>
      <dc:date>2022-02-08T22:15:27Z</dc:date>
    </item>
  </channel>
</rss>

