<?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: Datetime value as character in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Datetime-value-as-character/m-p/758290#M239407</link>
    <description>&lt;P&gt;&lt;EM&gt;&amp;gt;&amp;nbsp;If I want to display value with timezone(Z) then which format to use? I'm unable to find the right ISO 8601 format.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;At the top of the page linked:&amp;nbsp;&lt;/P&gt;
&lt;TABLE class="largeSpace" cellspacing="0" cellpadding="5"&gt;
&lt;TBODY&gt;
&lt;TR align="left" valign="top"&gt;
&lt;TD&gt;Z&lt;/TD&gt;
&lt;TD align="left"&gt;
&lt;P&gt;indicates that the time value is the time in Greenwich, England, or UTC time.&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
    <pubDate>Thu, 29 Jul 2021 22:16:29 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2021-07-29T22:16:29Z</dc:date>
    <item>
      <title>Datetime value as character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Datetime-value-as-character/m-p/758047#M239329</link>
      <description>&lt;P&gt;I want to display the datetime value as character as shown in format below. I tried with datetime16.format &amp;nbsp;like&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;put(datetime(),&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;datetime16.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;) &lt;/FONT&gt;but it's not producing the desired results. Any leads?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;2021-05-01T22:04:42Z&lt;/PRE&gt;</description>
      <pubDate>Thu, 29 Jul 2021 17:02:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Datetime-value-as-character/m-p/758047#M239329</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2021-07-29T17:02:56Z</dc:date>
    </item>
    <item>
      <title>Re: Datetime value as character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Datetime-value-as-character/m-p/758049#M239330</link>
      <description>&lt;P&gt;Look at the ISO formats &lt;A href="https://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a003169814.htm" target="_blank"&gt;https://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a003169814.htm&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jul 2021 11:38:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Datetime-value-as-character/m-p/758049#M239330</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-07-29T11:38:03Z</dc:date>
    </item>
    <item>
      <title>Re: Datetime value as character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Datetime-value-as-character/m-p/758060#M239335</link>
      <description>data _null_;&lt;BR /&gt;x=put(datetime(),e8601dt.);&lt;BR /&gt;put x=;&lt;BR /&gt;run;</description>
      <pubDate>Thu, 29 Jul 2021 12:33:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Datetime-value-as-character/m-p/758060#M239335</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-07-29T12:33:08Z</dc:date>
    </item>
    <item>
      <title>Re: Datetime value as character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Datetime-value-as-character/m-p/758159#M239365</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp;If I want to display value with timezone(Z) then which format to use? I'm unable to find the right ISO 8601 format.&lt;/P&gt;
&lt;P&gt;Desired value is,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;2021-05-01T22:04:42Z&lt;/PRE&gt;</description>
      <pubDate>Thu, 29 Jul 2021 17:05:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Datetime-value-as-character/m-p/758159#M239365</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2021-07-29T17:05:00Z</dc:date>
    </item>
    <item>
      <title>Re: Datetime value as character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Datetime-value-as-character/m-p/758161#M239366</link>
      <description>&lt;P&gt;Have you tried&amp;nbsp;&lt;SPAN&gt;E8601DZ&lt;/SPAN&gt;&lt;SPAN class="emph"&gt;w.d?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
	x=put(datetime(),E8601DZ20.);
	put x=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Yields the below in my environment (9.4 M6)&lt;/P&gt;
&lt;PRE&gt;x=2021-07-29T12:11:29Z
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="emph"&gt;If you want the actual offset, you would just extend the width of the format.&amp;nbsp; For example:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
	x=put(datetime(),E8601DZ27.);
	put x=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN class="emph"&gt;Yields:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;x=2021-07-29T12:20:44+00:00&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN class="emph"&gt;Jim&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jul 2021 17:23:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Datetime-value-as-character/m-p/758161#M239366</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2021-07-29T17:23:16Z</dc:date>
    </item>
    <item>
      <title>Re: Datetime value as character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Datetime-value-as-character/m-p/758290#M239407</link>
      <description>&lt;P&gt;&lt;EM&gt;&amp;gt;&amp;nbsp;If I want to display value with timezone(Z) then which format to use? I'm unable to find the right ISO 8601 format.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;At the top of the page linked:&amp;nbsp;&lt;/P&gt;
&lt;TABLE class="largeSpace" cellspacing="0" cellpadding="5"&gt;
&lt;TBODY&gt;
&lt;TR align="left" valign="top"&gt;
&lt;TD&gt;Z&lt;/TD&gt;
&lt;TD align="left"&gt;
&lt;P&gt;indicates that the time value is the time in Greenwich, England, or UTC time.&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Thu, 29 Jul 2021 22:16:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Datetime-value-as-character/m-p/758290#M239407</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-07-29T22:16:29Z</dc:date>
    </item>
    <item>
      <title>Re: Datetime value as character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Datetime-value-as-character/m-p/758306#M239415</link>
      <description>I have already tried with B8601dz. and E8601dz formats. It's not producing&lt;BR /&gt;the desired results.&lt;BR /&gt;</description>
      <pubDate>Fri, 30 Jul 2021 01:30:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Datetime-value-as-character/m-p/758306#M239415</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2021-07-30T01:30:17Z</dc:date>
    </item>
    <item>
      <title>Re: Datetime value as character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Datetime-value-as-character/m-p/758309#M239417</link>
      <description>&lt;P&gt;&lt;EM&gt;&amp;gt; It's not producing&amp;nbsp;the desired results.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;How?&lt;/P&gt;
&lt;P&gt;How can you say that when&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/37107"&gt;@jimbarbour&lt;/a&gt;&amp;nbsp;gave you the full exact code to exactly match the output you requested?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Jul 2021 01:53:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Datetime-value-as-character/m-p/758309#M239417</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-07-30T01:53:18Z</dc:date>
    </item>
    <item>
      <title>Re: Datetime value as character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Datetime-value-as-character/m-p/758310#M239418</link>
      <description>Hmmm.  That's the correct Format.  I'm scratching my head here.  I don't understand  why it's not working.&lt;BR /&gt;&lt;BR /&gt;Can you show us the code, the results your getting, and the log?  &lt;BR /&gt;&lt;BR /&gt;What are your locale settings? Maybe your locale setting is altering how the format works.&lt;BR /&gt;&lt;BR /&gt;What width are you specifying with the format?  Maybe try at least 27, maybe more if you want fractions of seconds.&lt;BR /&gt;&lt;BR /&gt;Jim</description>
      <pubDate>Fri, 30 Jul 2021 02:09:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Datetime-value-as-character/m-p/758310#M239418</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2021-07-30T02:09:16Z</dc:date>
    </item>
    <item>
      <title>Re: Datetime value as character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Datetime-value-as-character/m-p/758317#M239423</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I want to display the datetime value as character as shown in format below. I tried with datetime16.format &amp;nbsp;like&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;put(datetime(),&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;datetime16.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;) &lt;/FONT&gt;but it's not producing the desired results. Any leads?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;2021-05-01T22:04:42Z&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;In SAS formats convert values into text and informats convert text into values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the message you posted DATETIME is the only &lt;STRONG&gt;FORMAT&lt;/STRONG&gt; that you mentioned.&amp;nbsp; But the DATETIME format does not display dates in the style of the text you are showing.&amp;nbsp; It uses the DATE format style for the date part and then appends the time part with a colon separator.&amp;nbsp; And if you use a width of only 16 then it will only have room for two digits for the year part.&lt;/P&gt;
&lt;PRE&gt;1219  data test;
1220    have=dhms(mdy(5,1,2021),22,04,42);
1221    put 'COMMA20.   : ' have comma20.
1222      / 'DATETIME16.: ' have datetime16.
1223      / 'datetime19.: ' have datetime19.
1224      / 'E8601DZ20. : ' have E8601DZ20.
1225    ;
1226  run;

COMMA20.   :        1,935,525,882
DATETIME16.: 01MAY21:22:04:42
datetime19.:  01MAY2021:22:04:42
E8601DZ20. : 2021-05-01T22:04:42Z
&lt;/PRE&gt;
&lt;P&gt;If your source data is actual a character variable, instead of a numeric variable with a datetime value (number of seconds since 1960) then you will first need to convert the string into a datetime value.&amp;nbsp; You can do that by using an &lt;STRONG&gt;INFORMAT&lt;/STRONG&gt; with the INPUT() function.&amp;nbsp; You will need to create a new numeric variable to store the value since you cannot store a number into a character variable.&amp;nbsp; You might use the PUT() function with appropriate format to convert the datetime value back to a string, but if you already have it as a string in the style you want what is it that you want to change?&lt;/P&gt;</description>
      <pubDate>Fri, 30 Jul 2021 04:13:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Datetime-value-as-character/m-p/758317#M239423</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-07-30T04:13:06Z</dc:date>
    </item>
    <item>
      <title>Re: Datetime value as character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Datetime-value-as-character/m-p/758331#M239435</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I have already tried with B8601dz. and E8601dz formats. It's not producing&lt;BR /&gt;the desired results.&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT size="6"&gt;&lt;STRONG&gt;SHOW.YOUR.CODE.AND.LOG.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="4"&gt;And the "undesired" results.&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Jul 2021 06:13:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Datetime-value-as-character/m-p/758331#M239435</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-07-30T06:13:03Z</dc:date>
    </item>
  </channel>
</rss>

