<?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: SAS datetime conversion in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-datetime-conversion/m-p/909539#M358729</link>
    <description>&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Want;
  set Have;
  MyDateTime = MyDateTime + '24:00't;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 22 Dec 2023 22:55:30 GMT</pubDate>
    <dc:creator>SASKiwi</dc:creator>
    <dc:date>2023-12-22T22:55:30Z</dc:date>
    <item>
      <title>SAS datetime conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-datetime-conversion/m-p/909538#M358728</link>
      <description>&lt;P&gt;I want to add 24 hrs to DTC = 2023-10-16T09:30 so as to get the result as 2023-10-17T09:30. How should I write the SAS code?&lt;/P&gt;</description>
      <pubDate>Fri, 22 Dec 2023 22:49:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-datetime-conversion/m-p/909538#M358728</guid>
      <dc:creator>DeniseDorland</dc:creator>
      <dc:date>2023-12-22T22:49:17Z</dc:date>
    </item>
    <item>
      <title>Re: SAS datetime conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-datetime-conversion/m-p/909539#M358729</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Want;
  set Have;
  MyDateTime = MyDateTime + '24:00't;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 22 Dec 2023 22:55:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-datetime-conversion/m-p/909539#M358729</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2023-12-22T22:55:30Z</dc:date>
    </item>
    <item>
      <title>Re: SAS datetime conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-datetime-conversion/m-p/909541#M358730</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="DeniseDorland_0-1703285915674.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/92041iCFE1EDC97921F3BC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="DeniseDorland_0-1703285915674.png" alt="DeniseDorland_0-1703285915674.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;getting this error&lt;/P&gt;</description>
      <pubDate>Fri, 22 Dec 2023 22:59:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-datetime-conversion/m-p/909541#M358730</guid>
      <dc:creator>DeniseDorland</dc:creator>
      <dc:date>2023-12-22T22:59:04Z</dc:date>
    </item>
    <item>
      <title>Re: SAS datetime conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-datetime-conversion/m-p/909542#M358731</link>
      <description>&lt;P&gt;Since both DATETIME and TIME values are stored in seconds the easiest way is to add 24 hours worth of seconds, or '24:00:00't .&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  new_var = old_var + '24:00:00't ;
  format new_var datetime19.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 22 Dec 2023 23:00:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-datetime-conversion/m-p/909542#M358731</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-12-22T23:00:58Z</dc:date>
    </item>
    <item>
      <title>Re: SAS datetime conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-datetime-conversion/m-p/909544#M358732</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="DeniseDorland_0-1703286238020.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/92042iF42A82AAC38768D4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="DeniseDorland_0-1703286238020.png" alt="DeniseDorland_0-1703286238020.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;still getting the error&lt;/P&gt;</description>
      <pubDate>Fri, 22 Dec 2023 23:04:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-datetime-conversion/m-p/909544#M358732</guid>
      <dc:creator>DeniseDorland</dc:creator>
      <dc:date>2023-12-22T23:04:07Z</dc:date>
    </item>
    <item>
      <title>Re: SAS datetime conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-datetime-conversion/m-p/909545#M358733</link>
      <description>&lt;P&gt;You cannot add character strings.&lt;/P&gt;
&lt;P&gt;You will have to first convert the character string into an actual datetime value.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;input(dct_trt_1,anydtdtm20.) + '24:00:00't &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Do you want get a datetime value back?&amp;nbsp; or do you want another character string?&lt;/P&gt;</description>
      <pubDate>Fri, 22 Dec 2023 23:04:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-datetime-conversion/m-p/909545#M358733</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-12-22T23:04:23Z</dc:date>
    </item>
    <item>
      <title>Re: SAS datetime conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-datetime-conversion/m-p/909546#M358734</link>
      <description>Answer: 2023-10-17T09:30</description>
      <pubDate>Fri, 22 Dec 2023 23:07:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-datetime-conversion/m-p/909546#M358734</guid>
      <dc:creator>DeniseDorland</dc:creator>
      <dc:date>2023-12-22T23:07:34Z</dc:date>
    </item>
    <item>
      <title>Re: SAS datetime conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-datetime-conversion/m-p/909547#M358735</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/460911"&gt;@DeniseDorland&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Answer: 2023-10-17T09:30&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Huh?&lt;/P&gt;
&lt;P&gt;Do you want a character string? Or a number?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you plan on doing more arithmetic with this new datetime value? If so keep it as a number, otherwise you will have to convert it back from character again.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Dec 2023 23:35:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-datetime-conversion/m-p/909547#M358735</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-12-22T23:35:35Z</dc:date>
    </item>
    <item>
      <title>Re: SAS datetime conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-datetime-conversion/m-p/909548#M358736</link>
      <description>&lt;P&gt;Your DTC_TRT_1 variablef, and therefore like the others, are CHARACTER values. They are character values that will not convert to a "nice" numeric datetime value unless you force such. When you use a character variable in arithmetic SAS will attempt to convert it to a number but has very limited rules when the value is more complex than something like "123". So it is up to you to do several things: 1) convert the string to a datetime value to use in the addition.&lt;/P&gt;
&lt;P&gt;If the result is a new numeric&amp;nbsp; variable then you will want to assign a FORMAT to display the value in a manner that people can recognize.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data example;
   dtc_trt_1 ="2023-10-16T09:30";
   dtc_wsh =    input(dtc_trt_1,e8601dt.) +'24:00't;
   format dtc_wsh e8601dt.;
run;&lt;/PRE&gt;
&lt;P&gt;Note that I create a variable that is character as your LOG states for dtc_trt_1. Then use the INPUT function with an appropriate INFORMAT to create a datetime numeric value then add the time literal 24 hours. The shortest default format SAS has supplied that matches your appearance will have 19 characters so will display seconds as :00. If that is objectionable then it is possible to create a custom format that does otherwise.&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, times and datetime values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please do yourself an us a favor and copy the text from log and on the forum open a text box using the &amp;lt;/&amp;gt; icon above the message window and paste the text. That way we can copy/paste/edit your text. If we have to retype considerable amounts of text to answer questions you may not get as good or complete an answer.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Dec 2023 23:38:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-datetime-conversion/m-p/909548#M358736</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-12-22T23:38:03Z</dc:date>
    </item>
    <item>
      <title>Re: SAS datetime conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-datetime-conversion/m-p/909549#M358737</link>
      <description>&lt;P&gt;If you just want to make another string it might be easier to just convert the beginning of your string to a DATE value and then subtract one before converting it back into a string.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;dtc_wsh = put(input(dtc_trt_1,yymmdd10.)-1,yymmdd10.)||substr(ctc_trt_1,11,5);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or perhaps simpler to copy the string first (then you get a variable with the same length as the original) and then replace the first 10 characters with the new date.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;dtc_wsh = dtc_trt_1;
substr(dtc_wsh,1,10) =put(input(dtc_trt_1,yymmdd10.)-1,yymmdd10.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Dec 2023 23:46:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-datetime-conversion/m-p/909549#M358737</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-12-22T23:46:19Z</dc:date>
    </item>
    <item>
      <title>Re: SAS datetime conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-datetime-conversion/m-p/909601#M358754</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/460911"&gt;@DeniseDorland&lt;/a&gt; - I'm curious to know why your datetime is stored in a character variable - is that by design or just the way it was imported into SAS? As you can see, doing calculations on a character datetime is a whole lot harder than if it was a SAS datatime which is stored in a numeric variable.&lt;/P&gt;</description>
      <pubDate>Sun, 24 Dec 2023 21:07:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-datetime-conversion/m-p/909601#M358754</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2023-12-24T21:07:35Z</dc:date>
    </item>
  </channel>
</rss>

