<?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: dhms datetime conversion in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/dhms-datetime-conversion/m-p/505986#M135568</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Please avoid coding all in uppercase, its like your shouting at me.&amp;nbsp; Also please use the code window for code - its the {i} above post.&amp;nbsp; This:&lt;BR /&gt;&lt;SPAN&gt;DATETIME=DHMS(DTDATE,0,0,DTTIME);&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The dhms() function accepts:&lt;/P&gt;
&lt;P&gt;dhms(&amp;lt;date&amp;gt;,number of hours,number of minutes,number of seconds)&lt;/P&gt;
&lt;P&gt;You have put 0,0, then a very large number which is what is stored behind a time value.&amp;nbsp; Dates are number of days since cuttoff.&amp;nbsp; Time is number of seconds past midnight.&amp;nbsp; What you want to do is split the time per the function parameters:&lt;/P&gt;
&lt;PRE&gt;datatime=dhms(dtdate,hour(dttime),minute(dttime),second(dttime));&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If the value really is a TIME value (number of seconds since midnight)&amp;nbsp; then using 0,0,seconds is what you want to do.&amp;nbsp; Converting the seconds into hours, minutes and seconds and then passing them separately is really just wasted effort.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that the HOUR(), MINUTE() and SECOND() functions will work on both TIME and DATETIME values. Basically they ignore the "date" part of a datetime value (any value larger than 24 hours).&amp;nbsp; So you could also use one of these:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;datatime=dhms(dtdate,0,0,timepart(dttime));
datatime=dhms(dtdate,0,0,mod(dttime,'24:00't));
datatime=dhms(dtdate,0,0,mod(dttime,24*60*60));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 19 Oct 2018 15:37:44 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2018-10-19T15:37:44Z</dc:date>
    <item>
      <title>dhms datetime conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dhms-datetime-conversion/m-p/505924#M135541</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I used the following code to combine date and time data to create a datetime variable. However, the datetime variable is off. Help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA testing;&lt;BR /&gt;SET raw;&lt;BR /&gt;DATETIME=DHMS(DTDATE,0,0,DTTIME);&lt;BR /&gt;FORMAT DATETIME DATETIME16.;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SAS Output&lt;/P&gt;&lt;DIV class="branch"&gt;&lt;DIV&gt;&lt;DIV align="center"&gt;Obs dtDate dtTime DATETIME &lt;TABLE cellspacing="0" cellpadding="5"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;01/10/2016&lt;/TD&gt;&lt;TD&gt;23:29:00&lt;/TD&gt;&lt;TD&gt;11JAN16:22:58:00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;01/10/2016&lt;/TD&gt;&lt;TD&gt;23:30:00&lt;/TD&gt;&lt;TD&gt;11JAN16:23:00:00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;01/10/2016&lt;/TD&gt;&lt;TD&gt;23:31:00&lt;/TD&gt;&lt;TD&gt;11JAN16:23:02:00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;01/10/2016&lt;/TD&gt;&lt;TD&gt;23:32:00&lt;/TD&gt;&lt;TD&gt;11JAN16:23:04:00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;01/10/2016&lt;/TD&gt;&lt;TD&gt;23:33:00&lt;/TD&gt;&lt;TD&gt;11JAN16:23:06:00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;01/10/2016&lt;/TD&gt;&lt;TD&gt;23:34:00&lt;/TD&gt;&lt;TD&gt;11JAN16:23:08:00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;01/10/2016&lt;/TD&gt;&lt;TD&gt;23:35:00&lt;/TD&gt;&lt;TD&gt;11JAN16:23:10:00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;01/10/2016&lt;/TD&gt;&lt;TD&gt;23:36:00&lt;/TD&gt;&lt;TD&gt;11JAN16:23:12:00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;01/10/2016&lt;/TD&gt;&lt;TD&gt;23:37:00&lt;/TD&gt;&lt;TD&gt;11JAN16:23:14:00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;01/10/2016&lt;/TD&gt;&lt;TD&gt;23:38:00&lt;/TD&gt;&lt;TD&gt;11JAN16:23:16:&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 19 Oct 2018 14:05:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dhms-datetime-conversion/m-p/505924#M135541</guid>
      <dc:creator>lalaktgrau</dc:creator>
      <dc:date>2018-10-19T14:05:13Z</dc:date>
    </item>
    <item>
      <title>Re: dhms datetime conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dhms-datetime-conversion/m-p/505937#M135548</link>
      <description>&lt;P&gt;Please avoid coding all in uppercase, its like your shouting at me.&amp;nbsp; Also please use the code window for code - its the {i} above post.&amp;nbsp; This:&lt;BR /&gt;&lt;SPAN&gt;DATETIME=DHMS(DTDATE,0,0,DTTIME);&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The dhms() function accepts:&lt;/P&gt;
&lt;P&gt;dhms(&amp;lt;date&amp;gt;,number of hours,number of minutes,number of seconds)&lt;/P&gt;
&lt;P&gt;You have put 0,0, then a very large number which is what is stored behind a time value.&amp;nbsp; Dates are number of days since cuttoff.&amp;nbsp; Time is number of seconds past midnight.&amp;nbsp; What you want to do is split the time per the function parameters:&lt;/P&gt;
&lt;PRE&gt;datatime=dhms(dtdate,hour(dttime),minute(dttime),second(dttime));&lt;/PRE&gt;</description>
      <pubDate>Fri, 19 Oct 2018 14:21:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dhms-datetime-conversion/m-p/505937#M135548</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-10-19T14:21:20Z</dc:date>
    </item>
    <item>
      <title>Re: dhms datetime conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dhms-datetime-conversion/m-p/505961#M135563</link>
      <description>&lt;P&gt;When I run this code to simulate your data:&lt;/P&gt;
&lt;PRE&gt;data check;
   informat dtdate mmddyy10. dttime time8.;
   format dtdate mmddyy10. dttime time8.;
   input dtdate dttime;
   DATETIME=DHMS(DTDATE,0,0,DTTIME);
   format datetime datetime18.;
datalines;
01/10/2016 23:29:00 
01/10/2016 23:30:00 
01/10/2016 23:31:00 
01/10/2016 23:32:00 
01/10/2016 23:33:00 
01/10/2016 23:34:00 
01/10/2016 23:35:00 
01/10/2016 23:36:00 
01/10/2016 23:37:00 
01/10/2016 23:38:00 
;
run;&lt;/PRE&gt;
&lt;P&gt;I get&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;    dtdate      dttime              DATETIME

01/10/2016    23:29:00      10JAN16:23:29:00
01/10/2016    23:30:00      10JAN16:23:30:00
01/10/2016    23:31:00      10JAN16:23:31:00
01/10/2016    23:32:00      10JAN16:23:32:00
01/10/2016    23:33:00      10JAN16:23:33:00
01/10/2016    23:34:00      10JAN16:23:34:00
01/10/2016    23:35:00      10JAN16:23:35:00
01/10/2016    23:36:00      10JAN16:23:36:00
01/10/2016    23:37:00      10JAN16:23:37:00
01/10/2016    23:38:00      10JAN16:23:38:00



&lt;/PRE&gt;
&lt;P&gt;I would check your date variable to see if there is a decimal portion, which would represent a fraction of day or if the "time" value comes from an interval it may be exceeding 24 hours.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that if you run this code formatted value of date appears to match the one you show but when used with dhms you get quite a chunk of the day added to the time portion.&lt;/P&gt;
&lt;PRE&gt;data junk;
   date = '01JAN2016'd + .5;
   put date date9.;
   datetime = dhms(date,0,0,0);
   put datetime datetime16.;
run;&lt;/PRE&gt;</description>
      <pubDate>Fri, 19 Oct 2018 14:58:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dhms-datetime-conversion/m-p/505961#M135563</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-10-19T14:58:34Z</dc:date>
    </item>
    <item>
      <title>Re: dhms datetime conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dhms-datetime-conversion/m-p/505986#M135568</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Please avoid coding all in uppercase, its like your shouting at me.&amp;nbsp; Also please use the code window for code - its the {i} above post.&amp;nbsp; This:&lt;BR /&gt;&lt;SPAN&gt;DATETIME=DHMS(DTDATE,0,0,DTTIME);&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The dhms() function accepts:&lt;/P&gt;
&lt;P&gt;dhms(&amp;lt;date&amp;gt;,number of hours,number of minutes,number of seconds)&lt;/P&gt;
&lt;P&gt;You have put 0,0, then a very large number which is what is stored behind a time value.&amp;nbsp; Dates are number of days since cuttoff.&amp;nbsp; Time is number of seconds past midnight.&amp;nbsp; What you want to do is split the time per the function parameters:&lt;/P&gt;
&lt;PRE&gt;datatime=dhms(dtdate,hour(dttime),minute(dttime),second(dttime));&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If the value really is a TIME value (number of seconds since midnight)&amp;nbsp; then using 0,0,seconds is what you want to do.&amp;nbsp; Converting the seconds into hours, minutes and seconds and then passing them separately is really just wasted effort.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that the HOUR(), MINUTE() and SECOND() functions will work on both TIME and DATETIME values. Basically they ignore the "date" part of a datetime value (any value larger than 24 hours).&amp;nbsp; So you could also use one of these:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;datatime=dhms(dtdate,0,0,timepart(dttime));
datatime=dhms(dtdate,0,0,mod(dttime,'24:00't));
datatime=dhms(dtdate,0,0,mod(dttime,24*60*60));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Oct 2018 15:37:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dhms-datetime-conversion/m-p/505986#M135568</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-10-19T15:37:44Z</dc:date>
    </item>
    <item>
      <title>Re: dhms datetime conversion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dhms-datetime-conversion/m-p/505991#M135572</link>
      <description>&lt;P&gt;It looks like for the example data posted that the "date" value does include the time as a fraction of a day (like how Excel would store it).&amp;nbsp; So adding the date with fraction of day and time caused the time to be doubled.&lt;/P&gt;
&lt;P&gt;Here is test using the first two values in original question.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
  input date :mmddyy. time :time. datetime :datetime. ;
  date2 = date + (time/'24:00't);
  datetime2 = dhms(date,0,0,time);
  datetime3 = dhms(date2,0,0,time);
  datetime4 = dhms(date2,0,0,0);
  datetime5 = dhms(int(date2),0,0,time);
  format date date2 date9. time time8. datetime: datetime20. ;
  put (_n_ _all_) (=/);
cards;
01/10/2016 23:29:00 11JAN16:22:58:00
01/10/2016 23:30:00 11JAN16:23:00:00
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;_N_=1
date=10JAN2016
time=23:29:00
datetime=11JAN2016:22:58:00
date2=10JAN2016
datetime2=10JAN2016:23:29:00
datetime3=11JAN2016:22:58:00
datetime4=10JAN2016:23:29:00
datetime5=10JAN2016:23:29:00

_N_=2
date=10JAN2016
time=23:30:00
datetime=11JAN2016:23:00:00
date2=10JAN2016
datetime2=10JAN2016:23:30:00
datetime3=11JAN2016:23:00:00
datetime4=10JAN2016:23:30:00
datetime5=10JAN2016:23:30:00&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Oct 2018 15:57:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dhms-datetime-conversion/m-p/505991#M135572</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-10-19T15:57:23Z</dc:date>
    </item>
  </channel>
</rss>

