<?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: Time conversion problem with DHMS() in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Time-conversion-problem-with-DHMS/m-p/549701#M152564</link>
    <description>&lt;P&gt;Hi Reeza, I am not sure of the original time type, it only shows the length and it is in character format($250), that is why I sub stringed the value by position. The original time value looks like "2018-04-20T20:38:12.124Z". Can I still use anydtdtm?&lt;/P&gt;</description>
    <pubDate>Tue, 09 Apr 2019 16:48:02 GMT</pubDate>
    <dc:creator>lydiawawa</dc:creator>
    <dc:date>2019-04-09T16:48:02Z</dc:date>
    <item>
      <title>Time conversion problem with DHMS()</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Time-conversion-problem-with-DHMS/m-p/549696#M152561</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a time variable that contains the values in the form of :&amp;nbsp;2018-04-20T20:38:12.124Z&lt;/P&gt;&lt;P&gt;I tried to convert it into sas date time with the following code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;value_year = input(substr(value,1,4), 4.);
value_month = input(substr(value,6,2), 2.);
value_day = input(substr(value,9,2), 2.);
date = MDY(value_month,value_day, value_year);
value_hour = input(substr(value,12,2), 2.);
value_minute = input(substr(value,15,2), 2.);
value_second = input(substr(value,18,6), 6.3);
sasdatetime = DHMS(date,value_hour,value_minute, value_second);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Now I'm hoping to calculate the difference between two time values after converting the original values to the form of "sasdatetime". The unit of the difference should be in minute and second (MM/SS).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example the time interval between:&lt;/P&gt;&lt;P&gt;2018-03-23T14:19:43.046Z&lt;/P&gt;&lt;P&gt;and&lt;/P&gt;&lt;P&gt;2018-03-28T02:56:37.460Z&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In minute and second.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Apr 2019 16:36:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Time-conversion-problem-with-DHMS/m-p/549696#M152561</guid>
      <dc:creator>lydiawawa</dc:creator>
      <dc:date>2019-04-09T16:36:02Z</dc:date>
    </item>
    <item>
      <title>Re: Time conversion problem with DHMS()</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Time-conversion-problem-with-DHMS/m-p/549698#M152563</link>
      <description>So your original value looks like 22018-04-20T20:38:12.124Z? What is the type and format?&lt;BR /&gt;&lt;BR /&gt;I think you can use INPUT() to do a direct conversion such as:&lt;BR /&gt;&lt;BR /&gt;input(value, anydtdtm.);&lt;BR /&gt;&lt;BR /&gt;Where are the variables you want to calculate the difference of - in the same row? You can do the standard math and then format it as a time variable so the time as hour minutes and seconds. &lt;BR /&gt;&lt;BR /&gt;diff = datevar1-datevar2;&lt;BR /&gt;format diff time8.;&lt;BR /&gt;</description>
      <pubDate>Tue, 09 Apr 2019 16:38:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Time-conversion-problem-with-DHMS/m-p/549698#M152563</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-04-09T16:38:54Z</dc:date>
    </item>
    <item>
      <title>Re: Time conversion problem with DHMS()</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Time-conversion-problem-with-DHMS/m-p/549701#M152564</link>
      <description>&lt;P&gt;Hi Reeza, I am not sure of the original time type, it only shows the length and it is in character format($250), that is why I sub stringed the value by position. The original time value looks like "2018-04-20T20:38:12.124Z". Can I still use anydtdtm?&lt;/P&gt;</description>
      <pubDate>Tue, 09 Apr 2019 16:48:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Time-conversion-problem-with-DHMS/m-p/549701#M152564</guid>
      <dc:creator>lydiawawa</dc:creator>
      <dc:date>2019-04-09T16:48:02Z</dc:date>
    </item>
    <item>
      <title>Re: Time conversion problem with DHMS()</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Time-conversion-problem-with-DHMS/m-p/549708#M152571</link>
      <description>anydtdtm will only give time up until minutes. I need to keep seconds too. I also made edits to my previous reply.</description>
      <pubDate>Tue, 09 Apr 2019 16:52:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Time-conversion-problem-with-DHMS/m-p/549708#M152571</guid>
      <dc:creator>lydiawawa</dc:creator>
      <dc:date>2019-04-09T16:52:42Z</dc:date>
    </item>
    <item>
      <title>Re: Time conversion problem with DHMS()</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Time-conversion-problem-with-DHMS/m-p/549714#M152576</link>
      <description>&lt;P&gt;Then find the appropriate INFORMAT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
x1='2018-03-23T14:19:43.046Z';
x2='2018-03-28T02:56:37.460Z';
y1=input(x1, b8601dz.);
y2=input(x2, b8601dz.);
diff = y2-y1;
format y1 y2 datetime32.4 diff time12.;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE class="table" aria-label="Data Set WORK.HAVE"&gt;&lt;CAPTION aria-label="Data Set WORK.HAVE"&gt;&amp;nbsp;&lt;/CAPTION&gt;&lt;COLGROUP&gt;&lt;COL /&gt;&lt;/COLGROUP&gt;&lt;COLGROUP&gt;&lt;COL /&gt;&lt;COL /&gt;&lt;COL /&gt;&lt;COL /&gt;&lt;COL /&gt;&lt;/COLGROUP&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="r header" scope="col"&gt;Obs&lt;/TH&gt;
&lt;TH class="header" scope="col"&gt;x1&lt;/TH&gt;
&lt;TH class="header" scope="col"&gt;x2&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;y1&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;y2&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;diff&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH class="r rowheader" scope="row"&gt;1&lt;/TH&gt;
&lt;TD class="data"&gt;2018-03-23T14:19:43.046Z&lt;/TD&gt;
&lt;TD class="data"&gt;2018-03-28T02:56:37.460Z&lt;/TD&gt;
&lt;TD class="r data"&gt;23MAR2018:14:19:43.0460&lt;/TD&gt;
&lt;TD class="r data"&gt;28MAR2018:02:56:37.4600&lt;/TD&gt;
&lt;TD class="r data"&gt;108:36:54&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Apr 2019 17:06:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Time-conversion-problem-with-DHMS/m-p/549714#M152576</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-04-09T17:06:03Z</dc:date>
    </item>
    <item>
      <title>Re: Time conversion problem with DHMS()</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Time-conversion-problem-with-DHMS/m-p/549716#M152578</link>
      <description>&lt;P&gt;SAS has ISO informats.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://support.sas.com/documentation/cdl/en/leforinforref/64790/HTML/default/viewer.htm#n0verk17pchh4vn1akrrv0b5w3r0.htm" target="_blank"&gt;https://support.sas.com/documentation/cdl/en/leforinforref/64790/HTML/default/viewer.htm#n0verk17pchh4vn1akrrv0b5w3r0.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
 str='2018-04-20T20:38:12.124Z';
 date1=input(str,E8601DZ25.);
 format date1 datetime25.3;
 put (_all_) (=);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;str=2018-04-20T20:38:12.124Z date1=20APR2018:20:38:12.124
&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 Apr 2019 17:07:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Time-conversion-problem-with-DHMS/m-p/549716#M152578</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-04-09T17:07:37Z</dc:date>
    </item>
    <item>
      <title>Re: Time conversion problem with DHMS()</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Time-conversion-problem-with-DHMS/m-p/549720#M152582</link>
      <description>&lt;P&gt;Is it possible to proc tabulate the mean among the difference of several dates and still maintain the time12. format? I tried to proc tabulate by mean, it returned a decimal number instead, even after I specified the format time12.&lt;/P&gt;</description>
      <pubDate>Tue, 09 Apr 2019 17:38:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Time-conversion-problem-with-DHMS/m-p/549720#M152582</guid>
      <dc:creator>lydiawawa</dc:creator>
      <dc:date>2019-04-09T17:38:41Z</dc:date>
    </item>
    <item>
      <title>Re: Time conversion problem with DHMS()</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Time-conversion-problem-with-DHMS/m-p/549727#M152586</link>
      <description>&lt;P&gt;Suppose I have the following set of time:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;15APR2018:16:06:20.9270&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 15APR2018:16:06:15.5750&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;15APR2018:16:05:53.9130&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 15APR2018:16:02:57.8270&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Already converted to b8601dz. You can find te difference between the next to previous term by using dif()&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now I hope to find out the mean difference by tabulation:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc tabulate data = have missing out=want;
     var interval;
     table (interval = "Time difference") * (N mean std min max);
     format interval time12.;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The table returns interval in decimal instead of MM:SS (time12.) format.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Apr 2019 17:37:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Time-conversion-problem-with-DHMS/m-p/549727#M152586</guid>
      <dc:creator>lydiawawa</dc:creator>
      <dc:date>2019-04-09T17:37:24Z</dc:date>
    </item>
    <item>
      <title>Re: Time conversion problem with DHMS()</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Time-conversion-problem-with-DHMS/m-p/549733#M152591</link>
      <description>&lt;P&gt;put the format on the statistic request.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc tabulate data = have missing out=want;
     var interval;
     table (interval = "Time difference") * (N mean*f=time12.3 std min*f=time12.3 max*f=time12.3);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 Apr 2019 18:00:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Time-conversion-problem-with-DHMS/m-p/549733#M152591</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-04-09T18:00:38Z</dc:date>
    </item>
  </channel>
</rss>

