<?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 How to Change a chracter in DateTime in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-Change-a-chracter-in-DateTime/m-p/418201#M102716</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I want to change one character or replace one character 'T' to ':' in datetime variable using SAS. If it is just few observations then I can use if-then-else statements but if there are thousands of records and they have different time values, how can I change it.&lt;/P&gt;&lt;P&gt;e.g. I have a time value as&lt;/P&gt;&lt;P&gt;'2017-12-01T12:43:28-05:00' and I have to replace T with (colon &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; '2017-12-01:12:43:28-05:00'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; date_time = &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'2017-12-01T12:43:28-05:00'&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;then&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; date_time = &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'2017-12-01:12:43:28-05:00'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;It works with if-then-else to replace T with colon but I have different dates and times and I have thousands of records to do it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is greatly appreciated.&lt;/P&gt;</description>
    <pubDate>Mon, 04 Dec 2017 15:58:21 GMT</pubDate>
    <dc:creator>Malathi13</dc:creator>
    <dc:date>2017-12-04T15:58:21Z</dc:date>
    <item>
      <title>How to Change a chracter in DateTime</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Change-a-chracter-in-DateTime/m-p/418201#M102716</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I want to change one character or replace one character 'T' to ':' in datetime variable using SAS. If it is just few observations then I can use if-then-else statements but if there are thousands of records and they have different time values, how can I change it.&lt;/P&gt;&lt;P&gt;e.g. I have a time value as&lt;/P&gt;&lt;P&gt;'2017-12-01T12:43:28-05:00' and I have to replace T with (colon &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; '2017-12-01:12:43:28-05:00'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; date_time = &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'2017-12-01T12:43:28-05:00'&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;then&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; date_time = &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'2017-12-01:12:43:28-05:00'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;It works with if-then-else to replace T with colon but I have different dates and times and I have thousands of records to do it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is greatly appreciated.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Dec 2017 15:58:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Change-a-chracter-in-DateTime/m-p/418201#M102716</guid>
      <dc:creator>Malathi13</dc:creator>
      <dc:date>2017-12-04T15:58:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to Change a chracter in DateTime</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Change-a-chracter-in-DateTime/m-p/418206#M102719</link>
      <description>&lt;P&gt;So you have a&amp;nbsp;&lt;U&gt;&lt;STRONG&gt;character&lt;/STRONG&gt;&lt;/U&gt; field which contains ISO dates and you want to change T to a colon.&amp;nbsp; Is this what you are asking?&amp;nbsp; If so then you can use the tranwrd() function.&amp;nbsp; However, that being said, it really isn't a good idea to do this.&amp;nbsp; ISO dates are standard datetime format character data, and removing the T makes them no longer a compatible data item.&amp;nbsp; So the question is why do you want to do this?&amp;nbsp; Is it because you want to have a date, date/time numeric SAS variable?&amp;nbsp; If so then read them in using the appropriate format, e8601dt generally works for me.&amp;nbsp; Need more info really, but really don't change T to : for no apparent reason.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Dec 2017 16:13:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Change-a-chracter-in-DateTime/m-p/418206#M102719</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-12-04T16:13:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to Change a chracter in DateTime</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Change-a-chracter-in-DateTime/m-p/418208#M102721</link>
      <description>&lt;P&gt;Use SUBSTR - RIGHT option to replace the T&lt;/P&gt;
&lt;P&gt;Or use INPUT to convert it directly to a SAS datetime and then you can apply whatever format you want afterwards.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data demo;

have='2017-12-01T12:43:28-05:00' ;
z=input(have, anydtdtm.); *Convert to SAS datetime;
format z datetime.;

have_char = have;
substr(have_char, 11, 1) = ':'; *replace character if desired;

run;

proc print data=demo;
run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 04 Dec 2017 16:17:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Change-a-chracter-in-DateTime/m-p/418208#M102721</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-12-04T16:17:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to Change a chracter in DateTime</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Change-a-chracter-in-DateTime/m-p/418213#M102724</link>
      <description>&lt;P&gt;Hi Reeza,&lt;/P&gt;&lt;P&gt;thank you so much for the help, I got the correct one with the substr function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;M&lt;/P&gt;</description>
      <pubDate>Mon, 04 Dec 2017 16:33:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Change-a-chracter-in-DateTime/m-p/418213#M102724</guid>
      <dc:creator>Malathi13</dc:creator>
      <dc:date>2017-12-04T16:33:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to Change a chracter in DateTime</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Change-a-chracter-in-DateTime/m-p/418218#M102725</link>
      <description>&lt;P&gt;Noticed, that you have a time zone offset in your datetime value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have a look at the doc, &lt;A href="http://go.documentation.sas.com/?docsetId=leforinforref&amp;amp;docsetTarget=n09mk4h1ba9wp1n1tc3e7x0eow8q.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_self"&gt;Reading Dates and Times By Using the ISO 860 Basic and Extended Notations &lt;/A&gt;there are specific informats that will make use of the time zone offset information.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data demo;
  have='2017-12-01T12:43:28-05:00';
  dt1 = input(have, anydtdtm.);
  dt2 = input(have, E8601DZ.);

  format dt: datetime19.;
run;

proc print data=demo;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 04 Dec 2017 16:56:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Change-a-chracter-in-DateTime/m-p/418218#M102725</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2017-12-04T16:56:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to Change a chracter in DateTime</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Change-a-chracter-in-DateTime/m-p/418219#M102726</link>
      <description>&lt;P&gt;Thank you Bruno_sas.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Dec 2017 16:53:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Change-a-chracter-in-DateTime/m-p/418219#M102726</guid>
      <dc:creator>Malathi13</dc:creator>
      <dc:date>2017-12-04T16:53:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to Change a chracter in DateTime</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Change-a-chracter-in-DateTime/m-p/418221#M102727</link>
      <description>&lt;P&gt;As a follow-up to my previous question, I'm also trying to calculate the difference (in minutes, seconds) from one time variable with other.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;e.g. difference in&lt;/P&gt;&lt;P&gt;'2017-12-01T12:47:19-05:00' and&lt;/P&gt;&lt;P&gt;'2017-12-01T12:54:36-05:00'. I'm not sure if I have to use INTCK or any other functions or just (time2-time1).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can someone suggest me on this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;M&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 04 Dec 2017 16:58:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Change-a-chracter-in-DateTime/m-p/418221#M102727</guid>
      <dc:creator>Malathi13</dc:creator>
      <dc:date>2017-12-04T16:58:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to Change a chracter in DateTime</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Change-a-chracter-in-DateTime/m-p/418232#M102729</link>
      <description>&lt;P&gt;Hi Bruno_sas,&lt;/P&gt;&lt;P&gt;your code worked and gives the +5 time zone instead of -5. e.g. for &amp;nbsp;01DEC2017:12:43:28, it gave me &amp;nbsp;01DEC2017:17:43:28. I think this is +5. I'm not sure how to work with time zones yet, maybe you are correct. I need to learn about time zones. But I really appreciate you giving me the code to work with the time zones.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot&lt;/P&gt;&lt;P&gt;M&lt;/P&gt;</description>
      <pubDate>Mon, 04 Dec 2017 17:37:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Change-a-chracter-in-DateTime/m-p/418232#M102729</guid>
      <dc:creator>Malathi13</dc:creator>
      <dc:date>2017-12-04T17:37:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to Change a chracter in DateTime</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Change-a-chracter-in-DateTime/m-p/418240#M102733</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/91804"&gt;@Malathi13&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;As a follow-up to my previous question, I'm also trying to calculate the difference (in minutes, seconds) from one time variable with other.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;e.g. difference in&lt;/P&gt;
&lt;P&gt;'2017-12-01T12:47:19-05:00' and&lt;/P&gt;
&lt;P&gt;'2017-12-01T12:54:36-05:00'. I'm not sure if I have to use INTCK or any other functions or just (time2-time1).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can someone suggest me on this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;M&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You can subtract datetimes to get the difference in seconds. And then you can convert that to the units of your choice.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can also use INTCK.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Dec 2017 17:45:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Change-a-chracter-in-DateTime/m-p/418240#M102733</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-12-04T17:45:52Z</dc:date>
    </item>
  </channel>
</rss>

