<?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 a weird string to a date-time format in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Convert-a-weird-string-to-a-date-time-format/m-p/677867#M204537</link>
    <description>&lt;P&gt;The problem with the informat e8601dt. is that it ignores the time zone adjustment which appears in the text string as -04:00&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would think the e8601dz. informat is more appropriate, it adjusts the datetime value by -4 hours and zero minutes, and is probably more correct in this situation.&lt;/P&gt;</description>
    <pubDate>Wed, 19 Aug 2020 16:51:23 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2020-08-19T16:51:23Z</dc:date>
    <item>
      <title>Convert a weird string to a date-time format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-a-weird-string-to-a-date-time-format/m-p/677851#M204530</link>
      <description>&lt;P&gt;I'm getting raw data files from a source that provides weird (albeit consistent) date-time values as such:&lt;/P&gt;&lt;DIV class="branch"&gt;&lt;DIV&gt;&lt;DIV align="center"&gt;&amp;nbsp;admit &lt;TABLE cellspacing="0" cellpadding="5"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;2020-08-06T02:04:00-04:00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2020-09-03T21:29:00-04:00&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P class="lia-align-left"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-align-left"&gt;It's a YYYY-MM-DD date, followed by "T", then a HH:MM:DD time, followed by "-04:00". What I want to have is a variable called new_admit to appear as DDMMMYYYY:HH:MM:SS with the HH being in military time. I'd also like this to be a numeric variable, such that I could subtract or add it to another variable of the same type.&lt;/P&gt;&lt;P class="lia-align-left"&gt;For example, the two values for variable "admit" above would become "new_admit" 06AUG2020:02:04:00 and 03SEP2020:21:29:00.&lt;/P&gt;&lt;P class="lia-align-left"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-align-left"&gt;Thanks!&lt;/P&gt;&lt;P class="lia-align-left"&gt;Andrew&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 19 Aug 2020 16:27:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-a-weird-string-to-a-date-time-format/m-p/677851#M204530</guid>
      <dc:creator>DocMartin</dc:creator>
      <dc:date>2020-08-19T16:27:42Z</dc:date>
    </item>
    <item>
      <title>Re: Convert a weird string to a date-time format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-a-weird-string-to-a-date-time-format/m-p/677859#M204533</link>
      <description>&lt;P&gt;Guru&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15410"&gt;@data_null__&lt;/a&gt;&amp;nbsp; wrote this solution in another thread-&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input datetm $30.;
cards;
2020-08-06T02:04:00-04:00
2020-09-03T21:29:00-04:00
;

data want;
 set have;
 new_date=input(datetm,e8601dt.);
 format new_date datetime20.;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Aug 2020 16:41:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-a-weird-string-to-a-date-time-format/m-p/677859#M204533</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-08-19T16:41:12Z</dc:date>
    </item>
    <item>
      <title>Re: Convert a weird string to a date-time format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-a-weird-string-to-a-date-time-format/m-p/677861#M204534</link>
      <description>&lt;P&gt;That looks like the E8601DT19. informat should work to convert a character value to a datetime&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;newvar = input(admit,e8601dt19.);&lt;/P&gt;
&lt;P&gt;format newvar datetime18.;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The above ignores the timezone as that appears to be your request.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You really wouldn't "add" likely variables of a similar type (datetime) but use the INTNX function to advance/decrease the values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354&lt;/A&gt; has a PDF with much information about dates.&lt;/P&gt;
&lt;DIV id="n09mk4h1ba9wp1n1tc3e7x0eow8q" class="xis-topic"&gt;
&lt;DIV id="p05rz1ood6uhonn1wipzp6j93fxa" class="xis-subTopic"&gt;
&lt;DIV id="p0geyhaz7l2p54n1d3lcy07lf7yo" class="xis-topicContent"&gt;
&lt;DIV id="n1j7h3vebj2x99n1psqtycoten7v" class="xis-table"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Wed, 19 Aug 2020 16:44:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-a-weird-string-to-a-date-time-format/m-p/677861#M204534</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-08-19T16:44:01Z</dc:date>
    </item>
    <item>
      <title>Re: Convert a weird string to a date-time format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-a-weird-string-to-a-date-time-format/m-p/677867#M204537</link>
      <description>&lt;P&gt;The problem with the informat e8601dt. is that it ignores the time zone adjustment which appears in the text string as -04:00&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would think the e8601dz. informat is more appropriate, it adjusts the datetime value by -4 hours and zero minutes, and is probably more correct in this situation.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Aug 2020 16:51:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-a-weird-string-to-a-date-time-format/m-p/677867#M204537</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-08-19T16:51:23Z</dc:date>
    </item>
    <item>
      <title>Re: Convert a weird string to a date-time format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-a-weird-string-to-a-date-time-format/m-p/677872#M204541</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;The problem with the informat e8601dt. is that it ignores the time zone adjustment which appears in the text string as -04:00&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would think the e8601dz. informat is more appropriate, it adjusts the datetime value by -4 hours and zero minutes, and is probably more correct in this situation.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Agree in general but the specific request appears to want to discard the timezone component. At least using the E8601DZ&amp;nbsp; informat&amp;nbsp; I couldn't get the desired results because my timezone is quite a bit off. (actually getting different day than requested for the second value)&lt;/P&gt;</description>
      <pubDate>Wed, 19 Aug 2020 17:05:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-a-weird-string-to-a-date-time-format/m-p/677872#M204541</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-08-19T17:05:16Z</dc:date>
    </item>
    <item>
      <title>Re: Convert a weird string to a date-time format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-a-weird-string-to-a-date-time-format/m-p/677873#M204542</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;The problem with the informat e8601dt. is that it ignores the time zone adjustment which appears in the text string as -04:00&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would think the e8601dz. informat is more appropriate, it adjusts the datetime value by -4 hours and zero minutes, and is probably more correct in this situation.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Agree in general but the specific request appears to want to discard the timezone component. At least using the E8601DZ&amp;nbsp; informat&amp;nbsp; I couldn't get the desired results because my timezone is quite a bit off. (actually getting different day than requested for the second value)&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;My concern is that the OP is unaware of the meaning of -04:00. Anyway, he or she can choose whether to use E8601DT. or E8601DZ.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Aug 2020 17:11:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-a-weird-string-to-a-date-time-format/m-p/677873#M204542</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-08-19T17:11:44Z</dc:date>
    </item>
  </channel>
</rss>

