<?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: Converting time to a numeric variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Converting-time-to-a-numeric-variable/m-p/407781#M99390</link>
    <description>&lt;P&gt;INTCK() is useful, but remember it is counting how many boundaries you cross. So depending on what you want to count make sure to use the right values for the last parameter.&amp;nbsp; The default for INTCK('hour',....) will be the number of times you move past 00 minutes.&amp;nbsp; So '10:59:59't to '11:00:01'T will count as one hour boundary crossed even though it is a difference of just a couple of seconds.&lt;/P&gt;</description>
    <pubDate>Thu, 26 Oct 2017 18:53:08 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2017-10-26T18:53:08Z</dc:date>
    <item>
      <title>Converting time to a numeric variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-time-to-a-numeric-variable/m-p/407760#M99377</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have calculated the time in hours (variable name timehrs) between two datetime variables. I have converted time in hours to time in minutes (timemin). Both of these variables have time formats on them. I'd like to use timemin as a numeric variable to use in bivariate and multivariable calculations. I cannot figure out how to use the actual time in either hours or minutes instead of SAS time. For instance, if the value of timemins should be 1632 minutes, the value being used in calculations is 5875200, which is SAS time. How do I convert timemins and timehrs to real minutes and hours?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My code:&lt;/P&gt;
&lt;P&gt;Data have;&lt;BR /&gt;set a;&lt;BR /&gt; by Study_Number;&lt;BR /&gt; btime=dhms(date_b, 0,0,time_b);&lt;BR /&gt; ctime=dhms(date_c, 0,0,time_c);&lt;BR /&gt; timehrs=ctime-btime;&lt;BR /&gt; timemin=(timehrs*60);&lt;BR /&gt; format btime ctime datetime18. timemin timehrs time4.;&lt;BR /&gt;run;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Oct 2017 18:03:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-time-to-a-numeric-variable/m-p/407760#M99377</guid>
      <dc:creator>sarahsasuser</dc:creator>
      <dc:date>2017-10-26T18:03:50Z</dc:date>
    </item>
    <item>
      <title>Re: Converting time to a numeric variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-time-to-a-numeric-variable/m-p/407767#M99380</link>
      <description>&lt;P&gt;SAS stores TIME (and DATETIME) values in SECONDS, not hours or minutes.&lt;/P&gt;
&lt;P&gt;If you want to convert SECONDS to MINUTES then divide by 60.&amp;nbsp; To HOURS then divide by 60**2.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  bdt=dhms(date_b, 0,0,time_b);
  cdt=dhms(date_c, 0,0,time_c);
  timemin=(cdt-bdt)/60;
  timehrs=timemin/60;
  format bdt cdt datetime20. timemin timehrs F4.;
run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Don't attach TIME formats to numbers that aren't in seconds.&amp;nbsp; Also the DATETIME format does not display DATETIME19. properly. It will only show four digits for the year, even though it should be able to fit four digit years into 19 characters.&amp;nbsp; So use DATETIME20 instead.&lt;/P&gt;
&lt;P&gt;If you want to round the time to minutes or hours then you could use the ROUND()&amp;nbsp; function&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  timemin=round(cdt-bdt,60);
  timehrs=round(cdt-bdt,60**2);
  format timemin timehrs time8.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or you could use INTNX() function to truncate to MINUTE or HOUR.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  timemin=intnx('minute',cdt-bdt,0,'b');
  timehrs=intnx('hour',cdt-bdt,0,'b');
  format timemin timehrs time8.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you would still have a time value that you use with a TIME format.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Oct 2017 18:41:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-time-to-a-numeric-variable/m-p/407767#M99380</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-10-26T18:41:34Z</dc:date>
    </item>
    <item>
      <title>Re: Converting time to a numeric variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-time-to-a-numeric-variable/m-p/407773#M99383</link>
      <description>&lt;P&gt;Thanks Tom, I found the intick function to be the most efficient.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Oct 2017 18:41:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-time-to-a-numeric-variable/m-p/407773#M99383</guid>
      <dc:creator>sarahsasuser</dc:creator>
      <dc:date>2017-10-26T18:41:58Z</dc:date>
    </item>
    <item>
      <title>Re: Converting time to a numeric variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-time-to-a-numeric-variable/m-p/407781#M99390</link>
      <description>&lt;P&gt;INTCK() is useful, but remember it is counting how many boundaries you cross. So depending on what you want to count make sure to use the right values for the last parameter.&amp;nbsp; The default for INTCK('hour',....) will be the number of times you move past 00 minutes.&amp;nbsp; So '10:59:59't to '11:00:01'T will count as one hour boundary crossed even though it is a difference of just a couple of seconds.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Oct 2017 18:53:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-time-to-a-numeric-variable/m-p/407781#M99390</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-10-26T18:53:08Z</dc:date>
    </item>
  </channel>
</rss>

