<?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 calculation in SAS proc sql in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/time-calculation-in-SAS-proc-sql/m-p/487340#M126979</link>
    <description>&lt;PRE&gt;proc sql;
  create table mc_et as
  select sum(case when 5 &amp;lt; intnx('minutes',switch_time1,switch_time2) &amp;lt; 10 then 1 else 0 end) as count_of_8,&lt;BR /&gt;         ...
  from   have;
quit;&lt;/PRE&gt;
&lt;P&gt;Use the intnx function to find minutes difference, pop the range around the intnx function (assumes both are numeric times).&amp;nbsp; Code window which I have used above can be found as a {i} above post area - this retains code formatting and highlights it.&amp;nbsp; Again caps is like shouting.&lt;/P&gt;</description>
    <pubDate>Thu, 16 Aug 2018 10:52:46 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2018-08-16T10:52:46Z</dc:date>
    <item>
      <title>time calculation in SAS proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/time-calculation-in-SAS-proc-sql/m-p/487338#M126977</link>
      <description>&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;switch_time1&lt;/TD&gt;&lt;TD&gt;switch_time2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;8:00:15&lt;/TD&gt;&lt;TD&gt;8:32:15&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;9:12:13&lt;/TD&gt;&lt;TD&gt;9:18:13&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;18:20:36&lt;/TD&gt;&lt;TD&gt;18:46:36&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;how to use the right format of time calculation in SAS proc sql？&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE MC_ET AS&lt;BR /&gt;SELECT&lt;BR /&gt;sum(case when switch_time2-switch_time1&amp;gt;5 minutes and switch_time2-switch_time1&amp;lt;10mintues then 1 else 0 end) as Count_of_8,&lt;BR /&gt;sum(case when switch_time2-switch_time1&amp;gt;10 minutes and switch_time2-switch_time1&amp;lt;15mintues then 1 else 0 end as count_of_9, ...&lt;BR /&gt;FROM have&lt;BR /&gt;;&lt;BR /&gt;QUIT;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Aug 2018 10:36:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/time-calculation-in-SAS-proc-sql/m-p/487338#M126977</guid>
      <dc:creator>Geo-</dc:creator>
      <dc:date>2018-08-16T10:36:08Z</dc:date>
    </item>
    <item>
      <title>Re: time calculation in SAS proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/time-calculation-in-SAS-proc-sql/m-p/487340#M126979</link>
      <description>&lt;PRE&gt;proc sql;
  create table mc_et as
  select sum(case when 5 &amp;lt; intnx('minutes',switch_time1,switch_time2) &amp;lt; 10 then 1 else 0 end) as count_of_8,&lt;BR /&gt;         ...
  from   have;
quit;&lt;/PRE&gt;
&lt;P&gt;Use the intnx function to find minutes difference, pop the range around the intnx function (assumes both are numeric times).&amp;nbsp; Code window which I have used above can be found as a {i} above post area - this retains code formatting and highlights it.&amp;nbsp; Again caps is like shouting.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Aug 2018 10:52:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/time-calculation-in-SAS-proc-sql/m-p/487340#M126979</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-08-16T10:52:46Z</dc:date>
    </item>
    <item>
      <title>Re: time calculation in SAS proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/time-calculation-in-SAS-proc-sql/m-p/487341#M126980</link>
      <description>&lt;P&gt;Can't test at the moment, but pretty sure this works if these are SAS dates. Otherwise if they are strings just add an input function call.&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;create table MC_ET as&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;select &lt;/FONT&gt;&lt;FONT face="courier new,courier"&gt;sum( '00:05:00't &amp;lt; switch_time2-switch_time1 &amp;lt;= '00:10:00't ) as COUNT8&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ,sum( '00:10:00't &amp;lt; switch_time2-switch_time1 &amp;lt;= '00:15:00't ) as COUNT9&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;from HAVE;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Aug 2018 10:54:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/time-calculation-in-SAS-proc-sql/m-p/487341#M126980</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-08-16T10:54:17Z</dc:date>
    </item>
    <item>
      <title>Re: time calculation in SAS proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/time-calculation-in-SAS-proc-sql/m-p/487342#M126981</link>
      <description>&lt;P&gt;hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Check the intck function. Your data has to be in a time format (see&amp;nbsp; how to convert a time string in the example below).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lefunctionsref/63354/HTML/default/viewer.htm#p1md4mx2crzfaqn14va8kt7qvfhr.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lefunctionsref/63354/HTML/default/viewer.htm#p1md4mx2crzfaqn14va8kt7qvfhr.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 have;
informat switch_time1 switch_time2 hhmmss8.;
input switch_time1 switch_time2 str_time $;

time_diff=intck('minute',switch_time1, switch_time2);

conv_time=input(str_time,hhmmss8.);

cards;
8:00:15 8:32:15 8:32:15
9:12:13 9:18:13 9:18:13
18:20:36 18:46:36 18:46:36
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 16 Aug 2018 10:59:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/time-calculation-in-SAS-proc-sql/m-p/487342#M126981</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2018-08-16T10:59:34Z</dc:date>
    </item>
    <item>
      <title>Re: time calculation in SAS proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/time-calculation-in-SAS-proc-sql/m-p/487367#M126989</link>
      <description>&lt;P&gt;the syntax is right,how ever I got all the sum values equal 0,and the format of these two column are TIME8.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Aug 2018 12:11:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/time-calculation-in-SAS-proc-sql/m-p/487367#M126989</guid>
      <dc:creator>Geo-</dc:creator>
      <dc:date>2018-08-16T12:11:14Z</dc:date>
    </item>
    <item>
      <title>Re: time calculation in SAS proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/time-calculation-in-SAS-proc-sql/m-p/487368#M126990</link>
      <description>the syntax is right,how ever I got all the sum values equal 0,and the format of these two column are TIME8.</description>
      <pubDate>Thu, 16 Aug 2018 12:11:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/time-calculation-in-SAS-proc-sql/m-p/487368#M126990</guid>
      <dc:creator>Geo-</dc:creator>
      <dc:date>2018-08-16T12:11:34Z</dc:date>
    </item>
    <item>
      <title>Re: time calculation in SAS proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/time-calculation-in-SAS-proc-sql/m-p/487376#M126994</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/30622"&gt;@gamotte&lt;/a&gt;'s post should work, sorry I obviously meant intck rather than intnx.&amp;nbsp; Post some test data of what you have if it is not working for you, follow this post if needed:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Aug 2018 12:22:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/time-calculation-in-SAS-proc-sql/m-p/487376#M126994</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-08-16T12:22:02Z</dc:date>
    </item>
    <item>
      <title>Re: time calculation in SAS proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/time-calculation-in-SAS-proc-sql/m-p/487379#M126995</link>
      <description>&lt;P&gt;Show us your code and test data so that we can see the exact problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This works :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
informat switch_time1 switch_time2 hhmmss8.;
input switch_time1 switch_time2;
cards;
8:00:15 8:32:15 8:32:15
9:12:13 9:18:13 9:18:13
18:20:36 18:46:36 18:46:36
;
run;

proc sql;
    CREATE TABLE MC_ET AS
    SELECT case when intck("minute", switch_time1,switch_time2)&amp;gt;5 and intck("minute",switch_time1,switch_time2)&amp;lt;10 then 1 else 0 end AS betw5_10,
	       case when intck("minute", switch_time1,switch_time2)&amp;gt;10 and intck("minute",switch_time1,switch_time2)&amp;lt;15 then 1 else 0 end AS betw10_15,
        sum(CALCULATED betw5_10) as Count_of_8,
        sum(CALCULATED betw10_15) as Count_of_9
    FROM have
;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 16 Aug 2018 12:25:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/time-calculation-in-SAS-proc-sql/m-p/487379#M126995</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2018-08-16T12:25:41Z</dc:date>
    </item>
    <item>
      <title>Re: time calculation in SAS proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/time-calculation-in-SAS-proc-sql/m-p/487458#M127027</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/184018"&gt;@Geo-&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;the syntax is right,how ever I got all the sum values equal 0,and the format of these two column are TIME8.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Show exactly which code you submitted that is "right". Copy the code and any messages from the log. Paste into a code box opened with the forum's {I} icon.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I ask for that because the original Proc SQL code has a number of syntax errors&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;sum(case when switch_time2-switch_time1&amp;gt;5 minutes and &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&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;&lt;FONT color="#ff0000"&gt;^ERROR&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;switch_time2-switch_time1&amp;lt;10mintues then 1 else 0 end) as Count_of_8,&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&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; &lt;FONT color="#ff0000" face="Courier New"&gt;^ERROR&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000" face="arial,helvetica,sans-serif"&gt;As a minimum: you are either referencing a variable in correctly (minutes in the first error) or a not legally name variable (10mintues) in the second error.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000" face="arial,helvetica,sans-serif"&gt;SAS time values are stored as seconds. So any subtraction yields a number of seconds, not minutes.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000" face="arial,helvetica,sans-serif"&gt;Likely the results of all of your comparisons are FALSE so you get 0 for all of the values. But I do not see how this code even runs.&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Aug 2018 14:50:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/time-calculation-in-SAS-proc-sql/m-p/487458#M127027</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-08-16T14:50:04Z</dc:date>
    </item>
  </channel>
</rss>

