<?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 How to calculate the time difference between two observations of the single date variable in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-to-calculate-the-time-difference-between-two-observations-of/m-p/782583#M31896</link>
    <description>&lt;P&gt;Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt;,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a data set that contains the patients' dosing data. Every patient is supposed to take 2 doses daily every 12 hours (+-30 minutes). I need to calculate the difference between the time (per date per patient) and check which patients have or have not taken their doses correctly.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The data set has only the following two variables:&amp;nbsp;PT, Dose Time.&lt;/P&gt;&lt;P&gt;e.g.,&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;30SEP2021:22:31:00&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;30SEP2021:10:30:00&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;29SEP2021:22:28:00&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/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;Thank you so much and appreciate your help.&lt;/P&gt;</description>
    <pubDate>Fri, 26 Nov 2021 19:08:38 GMT</pubDate>
    <dc:creator>SAS_USER_928</dc:creator>
    <dc:date>2021-11-26T19:08:38Z</dc:date>
    <item>
      <title>How to calculate the time difference between two observations of the single date variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-calculate-the-time-difference-between-two-observations-of/m-p/782583#M31896</link>
      <description>&lt;P&gt;Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt;,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a data set that contains the patients' dosing data. Every patient is supposed to take 2 doses daily every 12 hours (+-30 minutes). I need to calculate the difference between the time (per date per patient) and check which patients have or have not taken their doses correctly.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The data set has only the following two variables:&amp;nbsp;PT, Dose Time.&lt;/P&gt;&lt;P&gt;e.g.,&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;30SEP2021:22:31:00&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;30SEP2021:10:30:00&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;29SEP2021:22:28:00&lt;/TD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;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;Thank you so much and appreciate your help.&lt;/P&gt;</description>
      <pubDate>Fri, 26 Nov 2021 19:08:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-calculate-the-time-difference-between-two-observations-of/m-p/782583#M31896</guid>
      <dc:creator>SAS_USER_928</dc:creator>
      <dc:date>2021-11-26T19:08:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate the time difference between two observations of the single date variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-calculate-the-time-difference-between-two-observations-of/m-p/782584#M31897</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* UNTESTED CODE */
data want;
    set have;
    by pt;
    delta_time=dose_time - lag(dose_time);
    if first.pt then delta_time=.;
    format delta_time time.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This assumes the data is properly sorted by PT and by dose_time. It also assumes that dose_time is numeric and not character.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want tested code, do not provide data as screen captures. Provide data using &lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;these instructions&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Fri, 26 Nov 2021 19:51:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-calculate-the-time-difference-between-two-observations-of/m-p/782584#M31897</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-11-26T19:51:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate the time difference between two observations of the single date variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-calculate-the-time-difference-between-two-observations-of/m-p/782586#M31898</link>
      <description>&lt;P&gt;Thank you so much&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;.&amp;nbsp;This did work. I just updated the following line to get the number of hours between two doses (I believe the prior result was in seconds?).&lt;/P&gt;&lt;P&gt;delta_time=dose_time - lag(dose_time)/3600;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note: The dose dates were in DateTime format.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much again for your prompt response and solution.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Nov 2021 19:56:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-calculate-the-time-difference-between-two-observations-of/m-p/782586#M31898</guid>
      <dc:creator>SAS_USER_928</dc:creator>
      <dc:date>2021-11-26T19:56:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate the time difference between two observations of the single date variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-calculate-the-time-difference-between-two-observations-of/m-p/782588#M31899</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/407996"&gt;@SAS_USER_928&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I believe you want&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;delta_time=(dose_time - lag(dose_time))/3600; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but since my original solution was formatted with the &lt;FONT face="courier new,courier"&gt;time.&lt;/FONT&gt; format, I don't see any benefit of doing this division.&lt;/P&gt;</description>
      <pubDate>Fri, 26 Nov 2021 20:06:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-calculate-the-time-difference-between-two-observations-of/m-p/782588#M31899</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-11-26T20:06:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate the time difference between two observations of the single date variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-calculate-the-time-difference-between-two-observations-of/m-p/782589#M31900</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That's correct. Sorry I probably deleted additional parenthesis while updating the original variables here for public use.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DELTA_TIME= ROUND((DOSE_DT_TIME- LAG(DOSE_DT_TIME))/3600, 0.01);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The original answer had values like 45000 etc. in the DELTA_TIME variable which I did not want. That's the reason I divided by 3600 to get something like 12(.35) (hours).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Fri, 26 Nov 2021 20:14:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-calculate-the-time-difference-between-two-observations-of/m-p/782589#M31900</guid>
      <dc:creator>SAS_USER_928</dc:creator>
      <dc:date>2021-11-26T20:14:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate the time difference between two observations of the single date variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-calculate-the-time-difference-between-two-observations-of/m-p/782592#M31901</link>
      <description>&lt;P&gt;Yes, I get that, but using the TIME. format essentially displays the result as (for example) 12:05:14&lt;/P&gt;</description>
      <pubDate>Fri, 26 Nov 2021 20:24:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-calculate-the-time-difference-between-two-observations-of/m-p/782592#M31901</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-11-26T20:24:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate the time difference between two observations of the single date variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-calculate-the-time-difference-between-two-observations-of/m-p/782609#M31902</link>
      <description>&lt;P&gt;Ah that TIME. formatted variable is perfect; I want it but cannot use to calculate/apply Mean statistics on it. That's why I created a new variable and converted to the numeric number of hours as well.&lt;/P&gt;</description>
      <pubDate>Fri, 26 Nov 2021 22:47:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-calculate-the-time-difference-between-two-observations-of/m-p/782609#M31902</guid>
      <dc:creator>SAS_USER_928</dc:creator>
      <dc:date>2021-11-26T22:47:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate the time difference between two observations of the single date variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-calculate-the-time-difference-between-two-observations-of/m-p/782610#M31903</link>
      <description>&lt;P&gt;OK now I need a little more help. The new variable that I created (that holds the number of hours) is not correct. Can you please help to use your TIME. formatted variable to calculate the number of hours (as number variable) so that I can apply Mean on it?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Fri, 26 Nov 2021 22:55:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-calculate-the-time-difference-between-two-observations-of/m-p/782610#M31903</guid>
      <dc:creator>SAS_USER_928</dc:creator>
      <dc:date>2021-11-26T22:55:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate the time difference between two observations of the single date variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-calculate-the-time-difference-between-two-observations-of/m-p/782611#M31904</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/407996"&gt;@SAS_USER_928&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Ah that TIME. formatted variable is perfect; I want it but cannot use to calculate/apply Mean statistics on it. That's why I created a new variable and converted to the numeric number of hours as well.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Incorrect. You can calculate means on it just as you can calculate means on any other number.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;OK now I need a little more help. The new variable that I created (that holds the number of hours) is not correct. Can you please help to use your TIME. formatted variable to calculate the number of hours (as number variable) so that I can apply Mean on it?&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;PROC MEANS will do it. It works just fine on formatted variables.&lt;/P&gt;</description>
      <pubDate>Fri, 26 Nov 2021 23:44:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-calculate-the-time-difference-between-two-observations-of/m-p/782611#M31904</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-11-26T23:44:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate the time difference between two observations of the single date variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-calculate-the-time-difference-between-two-observations-of/m-p/782613#M31905</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;No not in SAS application. I create a data set which I then import to a third party application (part of my job). They provide their own set of tests based on the types of variables. Mean was disabled for this character TIME formatted variable. That's the reason I need a numeric variable to hold the number of hours (as number and not as time).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help in the matter will be greatly appreciated. I am trying to get it to work but failing miserably.&lt;/P&gt;</description>
      <pubDate>Fri, 26 Nov 2021 23:54:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-calculate-the-time-difference-between-two-observations-of/m-p/782613#M31905</guid>
      <dc:creator>SAS_USER_928</dc:creator>
      <dc:date>2021-11-26T23:54:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate the time difference between two observations of the single date variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-calculate-the-time-difference-between-two-observations-of/m-p/782615#M31906</link>
      <description>&lt;P&gt;Then use the formula for hours I provided earlier.&lt;/P&gt;</description>
      <pubDate>Sat, 27 Nov 2021 10:42:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-calculate-the-time-difference-between-two-observations-of/m-p/782615#M31906</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-11-27T10:42:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate the time difference between two observations of the single date variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-calculate-the-time-difference-between-two-observations-of/m-p/799428#M33164</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This time I have a different situation and thought if you could please help... using SAS or Proc SQL.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a list of pts. that have to complete a lab every N (say between 4 to 5)&amp;nbsp;weeks and outside of this window will be considered NON COMPLIANT.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the list of PTs and their lab dates:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;PT&lt;/TD&gt;&lt;TD&gt;Date&lt;/TD&gt;&lt;TD&gt;Duration in Weeks&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1/5/2021&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;2/24/2021&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;4/7/2021&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;5/19/2021&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;1/14/2021&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;3/2/2021&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;2/25/2022&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My data is sorted by PT and Date in ascending order.&amp;nbsp; For PT1, I need to take the difference between every two labs and calculate the difference (duration) in weeks. If there is only 1 lab performed so far (as is the case with PT3) then use today's date to calculate the duration in weeks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanking you in advance for your help.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Mar 2022 19:20:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-calculate-the-time-difference-between-two-observations-of/m-p/799428#M33164</guid>
      <dc:creator>SAS_USER_928</dc:creator>
      <dc:date>2022-03-01T19:20:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate the time difference between two observations of the single date variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-calculate-the-time-difference-between-two-observations-of/m-p/799431#M33165</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    by pt;
    prev_date=lag(date);
    if first.pt then prev_date=.;
    duration_in_weeks = (date-prev_date)/7;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 01 Mar 2022 19:34:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-calculate-the-time-difference-between-two-observations-of/m-p/799431#M33165</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-03-01T19:34:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate the time difference between two observations of the single date variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-calculate-the-time-difference-between-two-observations-of/m-p/799455#M33166</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;.&amp;nbsp;There is only 1 scenario left out. See PT3 which has only one observation and I do not want to exclude that and want the Duration to be calculated as Extraction Date - (Lab) Date to see if the lab is past-due.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: Extraction Date is hard-code as 2022-03-01.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Tue, 01 Mar 2022 21:39:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-calculate-the-time-difference-between-two-observations-of/m-p/799455#M33166</guid>
      <dc:creator>SAS_USER_928</dc:creator>
      <dc:date>2022-03-01T21:39:19Z</dc:date>
    </item>
  </channel>
</rss>

