<?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 difference of 2 numeric variable in PROC SQL in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Time-difference-of-2-numeric-variable-in-PROC-SQL/m-p/858217#M82489</link>
    <description>&lt;P&gt;As&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13674"&gt;@LinusH&lt;/a&gt;&amp;nbsp;wrote, it is easy if you convert the values to SAS time values. In SQL, it can be done like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;                                                                                                                               
  create table want as select                                                                                                           
    hms(int(start_time/10000),mod(int(start_time/100),100),mod(start_time,100)) as start_time format=time8.,                            
    hms(int(end_time/10000),mod(int(end_time/100),100),mod(end_time,100)) as end_time format=time8.,                                    
    calculated end_time - calculated start_time as elapsed_time format=time8.                                                           
  from have;                                                                                                                            
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 10 Feb 2023 08:46:22 GMT</pubDate>
    <dc:creator>s_lassen</dc:creator>
    <dc:date>2023-02-10T08:46:22Z</dc:date>
    <item>
      <title>Time difference of 2 numeric variable in PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Time-difference-of-2-numeric-variable-in-PROC-SQL/m-p/857501#M82478</link>
      <description>&lt;P&gt;Hello guys,&lt;/P&gt;&lt;P&gt;I want to calcuate and express the time difference between two numeric variables in PROC SQL.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, start_time is 103027. It means that the start time is 10:30:27&lt;/P&gt;&lt;P&gt;and end_time is 114037. It means that the end time is 11:40:37.&lt;/P&gt;&lt;P&gt;Both variables are numeric type and their calculated time differnece is&amp;nbsp; 1 hour 10 minutes 10 seconds.&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I express PROC SQL in this logic?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you have any questions, please leave comment below.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2023 08:29:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Time-difference-of-2-numeric-variable-in-PROC-SQL/m-p/857501#M82478</guid>
      <dc:creator>Jack1208</dc:creator>
      <dc:date>2023-02-07T08:29:42Z</dc:date>
    </item>
    <item>
      <title>Re: Time difference of 2 numeric variable in PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Time-difference-of-2-numeric-variable-in-PROC-SQL/m-p/857505#M82479</link>
      <description>&lt;P&gt;I think it's best to convert the fields to SAS time format.&lt;/P&gt;
&lt;P&gt;For that, you should use SAS time informats.&lt;/P&gt;
&lt;P&gt;Once done, a simple subtraction will give you the difference in seconds, which in turn can apply a format so you can view it with minutes and hours.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/leforinforref/n0verk17pchh4vn1akrrv0b5w3r0.htm#p19bmyab1kchf7n168944frtxb1c" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/leforinforref/n0verk17pchh4vn1akrrv0b5w3r0.htm#p19bmyab1kchf7n168944frtxb1c&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2023 08:51:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Time-difference-of-2-numeric-variable-in-PROC-SQL/m-p/857505#M82479</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2023-02-07T08:51:09Z</dc:date>
    </item>
    <item>
      <title>Re: Time difference of 2 numeric variable in PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Time-difference-of-2-numeric-variable-in-PROC-SQL/m-p/857638#M82481</link>
      <description>&lt;P&gt;You should provide some example values and the time interpretation when you have&lt;/P&gt;
&lt;P&gt;1) hour is less than 10 and minutes and seconds greater than 10&lt;/P&gt;
&lt;P&gt;2) hour is greater than or equal to 10 and minutes less than 10 and seconds greater than 10&lt;/P&gt;
&lt;P&gt;3) hour is greater than or equal to 10 and minutes greater than 10 and seconds less than 10&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The above goes to what may be needed to create a valid SAS time value. If you have 10203 and in one place might be 1:02:03 (hours less than 10), 10:02:30 (minutes less than 10) or 10:20:03 (seconds less than 10) in another this process may not be doable at all. With the oddities I have seen people call times over the years I really want good examples before writing any code.&lt;/P&gt;
&lt;P&gt;Note: it may be easier to read from text with a proper informat than to convert existing numerical values that may have had information removed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are these values from a 12 hour clock or 24 hour clock? If 12 hour then you need to tell us how to know if 10:30:27 is AM or PM. Because without that information then your result could be 12 hours off. Or even if they are the same day?&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2023 18:52:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Time-difference-of-2-numeric-variable-in-PROC-SQL/m-p/857638#M82481</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-02-07T18:52:12Z</dc:date>
    </item>
    <item>
      <title>Re: Time difference of 2 numeric variable in PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Time-difference-of-2-numeric-variable-in-PROC-SQL/m-p/858217#M82489</link>
      <description>&lt;P&gt;As&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13674"&gt;@LinusH&lt;/a&gt;&amp;nbsp;wrote, it is easy if you convert the values to SAS time values. In SQL, it can be done like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;                                                                                                                               
  create table want as select                                                                                                           
    hms(int(start_time/10000),mod(int(start_time/100),100),mod(start_time,100)) as start_time format=time8.,                            
    hms(int(end_time/10000),mod(int(end_time/100),100),mod(end_time,100)) as end_time format=time8.,                                    
    calculated end_time - calculated start_time as elapsed_time format=time8.                                                           
  from have;                                                                                                                            
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 10 Feb 2023 08:46:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Time-difference-of-2-numeric-variable-in-PROC-SQL/m-p/858217#M82489</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2023-02-10T08:46:22Z</dc:date>
    </item>
    <item>
      <title>Re: Time difference of 2 numeric variable in PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Time-difference-of-2-numeric-variable-in-PROC-SQL/m-p/858229#M82490</link>
      <description>&lt;P&gt;I could not think of a simpler solution than one very similar to what &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/76464"&gt;@s_lassen&lt;/a&gt; has provided.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So to the original question from &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/439253"&gt;@Jack1208&lt;/a&gt; , you would be wise (if at all possible) to not store hours/minutes/seconds as an integer such as 103027 indicating 10 hours, 30 minutes, 27 seconds. Most databases and most programming languages have built in ways to store hours/minutes/seconds, better to store your data in one of those supported ways, rather than the way it is stored as 103027.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Feb 2023 11:26:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Time-difference-of-2-numeric-variable-in-PROC-SQL/m-p/858229#M82490</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-02-10T11:26:08Z</dc:date>
    </item>
  </channel>
</rss>

