<?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 Calculating average time (duration) in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Calculating-average-time-duration/m-p/52979#M14601</link>
    <description>Hello!&lt;BR /&gt;
I am a SPSS user who is now using SAS for the first time.  Things have been going pretty well but I am stumped with a particular issue.  I am hoping some of you experts out there will have an answer and be willing to help this newbie.  &lt;BR /&gt;
&lt;BR /&gt;
I am trying to calculate the length of time (mean, median, and mode) between when a record was created ("date reported" in my database) and when that same record was returned ("date closed" in my database).  The reason for the calculation is that I am trying to determine if a policy change has had an impact on the length of time it is taking people to close reports.  (Ultimately I want to see if there is a correlation between length of time and outcome of these reports but that's a topic for another day.)  These date fields are not "SAS" fields per se.  They are generated and captured by our Oracle database and then I read the field in SAS.  &lt;BR /&gt;
&lt;BR /&gt;
I have found plenty of information on how to return records within a specific interval but, so far, I am stumped on how to do an average.  I know you guys will make this look easy and I am prepared to be embarassed in the interest of getting this analysis completed.  &lt;BR /&gt;
&lt;BR /&gt;
Thanks in advance!</description>
    <pubDate>Thu, 09 Jul 2009 15:07:41 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2009-07-09T15:07:41Z</dc:date>
    <item>
      <title>Calculating average time (duration)</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Calculating-average-time-duration/m-p/52979#M14601</link>
      <description>Hello!&lt;BR /&gt;
I am a SPSS user who is now using SAS for the first time.  Things have been going pretty well but I am stumped with a particular issue.  I am hoping some of you experts out there will have an answer and be willing to help this newbie.  &lt;BR /&gt;
&lt;BR /&gt;
I am trying to calculate the length of time (mean, median, and mode) between when a record was created ("date reported" in my database) and when that same record was returned ("date closed" in my database).  The reason for the calculation is that I am trying to determine if a policy change has had an impact on the length of time it is taking people to close reports.  (Ultimately I want to see if there is a correlation between length of time and outcome of these reports but that's a topic for another day.)  These date fields are not "SAS" fields per se.  They are generated and captured by our Oracle database and then I read the field in SAS.  &lt;BR /&gt;
&lt;BR /&gt;
I have found plenty of information on how to return records within a specific interval but, so far, I am stumped on how to do an average.  I know you guys will make this look easy and I am prepared to be embarassed in the interest of getting this analysis completed.  &lt;BR /&gt;
&lt;BR /&gt;
Thanks in advance!</description>
      <pubDate>Thu, 09 Jul 2009 15:07:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Calculating-average-time-duration/m-p/52979#M14601</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-07-09T15:07:41Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating average time (duration)</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Calculating-average-time-duration/m-p/52980#M14602</link>
      <description>You will surely find plenty of statistic procedures/functions to suite your needs.&lt;BR /&gt;
&lt;BR /&gt;
But please be more specific about what you're trying to do.&lt;BR /&gt;
&lt;BR /&gt;
Could you please provide some of the input data and output data you expect to get?&lt;BR /&gt;
&lt;BR /&gt;
Cheers from Portugal.&lt;BR /&gt;
&lt;BR /&gt;
Daniel Santos @ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;.</description>
      <pubDate>Thu, 09 Jul 2009 15:23:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Calculating-average-time-duration/m-p/52980#M14602</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2009-07-09T15:23:15Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating average time (duration)</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Calculating-average-time-duration/m-p/52981#M14603</link>
      <description>Thank you for the quick reply!&lt;BR /&gt;
&lt;BR /&gt;
Let me try to be more specific about what I am trying to do.  To make this more clear, and for confidentiality reasons, I am going to use a different example than what I provided in my earlier post but this new example will speak to almost the exact same issue.  My new example is, "How long are people watching a specific TV channel?"   &lt;BR /&gt;
&lt;BR /&gt;
The data tell me when a person turned on the channel and when they turned off the channel.  I want to determine the average length of time viewers spent watching the channel.  I want to do this for all people who watched the channel.  When I pull my data, I will be pulling "All Viewers who Watched the Channel" during a specific month.  I will also pull "Time the Channel was Turned On" and "Time the Channel was Turned Off."  When my report is done, I want to be able to say All Viewers of this Channel watched the Channel for an Average of x Hours per Day during the Month we tracked. &lt;BR /&gt;
&lt;BR /&gt;
Does this make it more clear?  Please let me know.  Thank you!</description>
      <pubDate>Thu, 09 Jul 2009 15:50:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Calculating-average-time-duration/m-p/52981#M14603</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-07-09T15:50:00Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating average time (duration)</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Calculating-average-time-duration/m-p/52982#M14604</link>
      <description>OK.&lt;BR /&gt;
&lt;BR /&gt;
Assuming you have already the data in one row for each person (say, PERSON_ID, TV_ON_DATETIME, TV_OFF_DATETIME), The MEANS/SUMMARY procedures (they do pretty much the same) will sum the data in the many ways you need.&lt;BR /&gt;
&lt;BR /&gt;
See the online documentation here:&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/a000146728.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/a000146728.htm&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
Cheers from Portugal.&lt;BR /&gt;
&lt;BR /&gt;
Daniel Santos @ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;.</description>
      <pubDate>Thu, 09 Jul 2009 15:59:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Calculating-average-time-duration/m-p/52982#M14604</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2009-07-09T15:59:18Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating average time (duration)</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Calculating-average-time-duration/m-p/52983#M14605</link>
      <description>Perhaps a key in understanding the advise given is understanding what "time" is in SAS, it's the number of durations(days, seconds,etc..) from January 1, 1960. &lt;BR /&gt;
&lt;BR /&gt;
This note may be of some help&lt;BR /&gt;
&lt;BR /&gt;
&lt;A href="http://support.sas.com/kb/24/585.html" target="_blank"&gt;http://support.sas.com/kb/24/585.html&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
There is a lot of information on Date/Time usage in the SAS documentation, your task is a common one.&lt;BR /&gt;
&lt;BR /&gt;
regards,</description>
      <pubDate>Thu, 09 Jul 2009 16:22:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Calculating-average-time-duration/m-p/52983#M14605</guid>
      <dc:creator>Jay</dc:creator>
      <dc:date>2009-07-09T16:22:19Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating average time (duration)</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Calculating-average-time-duration/m-p/52984#M14606</link>
      <description>Thank you, Daniel and Jay, for your responses.  &lt;BR /&gt;
&lt;BR /&gt;
I am still having difficulty getting the return I am seeking.  I'll re-post showing both my code and results next week.  &lt;BR /&gt;
&lt;BR /&gt;
Thanks again!</description>
      <pubDate>Thu, 09 Jul 2009 17:06:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Calculating-average-time-duration/m-p/52984#M14606</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-07-09T17:06:32Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating average time (duration)</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Calculating-average-time-duration/m-p/52985#M14607</link>
      <description>Sounds as though you want to compute the time-elapsed between the two date/time values, resulting in a duration-value.  If stored in a character-format, each of the strings must be converted to a SAS DATETIME in order to work with it in expressions.  And, since the two events are a point in time and in SAS are represented as seconds since 1/1/1960, you can subtract the end from the start, to arrive at a duration (number representing seconds internally to SAS).  With this metric, you can compute/derive other stats, as required, and report the results as seconds, hour:min, or other "formatted" value using SAS code.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;BR /&gt;
&lt;BR /&gt;
About SAS Date, Time, and Datetime Values&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/lrcon/61722/HTML/default/a002200738.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrcon/61722/HTML/default/a002200738.htm&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
Processing ORACLE® Dates with SAS/ACCESS® in&lt;BR /&gt;
the UNIX® Environment - paper may or may not be useful&lt;BR /&gt;
&lt;A href="http://support.sas.com/techsup/technote/ts566d.pdf" target="_blank"&gt;http://support.sas.com/techsup/technote/ts566d.pdf&lt;/A&gt;</description>
      <pubDate>Thu, 09 Jul 2009 17:56:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Calculating-average-time-duration/m-p/52985#M14607</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-07-09T17:56:29Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating average time (duration)</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Calculating-average-time-duration/m-p/52986#M14608</link>
      <description>here's my quick friday stab at this.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
/* set up some artificial data */&lt;BR /&gt;
data EventData;&lt;BR /&gt;
  format EventID 8. EventOpenDT EventCloseDT datetime.;&lt;BR /&gt;
  do EventID=1 to 1000;&lt;BR /&gt;
    EventOpenDT =dhms('01jul2009'd, 0, 0, floor(ranuni(123)*24*60*60));&lt;BR /&gt;
    EventCloseDT=dhms('02jul2009'd, 0, 0, floor(ranuni(456)*24*60*60));&lt;BR /&gt;
    output;&lt;BR /&gt;
  end;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
/* calculate duration for each record in raw data*/&lt;BR /&gt;
data EventData;&lt;BR /&gt;
  set EventData;&lt;BR /&gt;
  EventDuration=intck('dthour', EventOpenDT, EventCloseDT);&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
/* summarize the duration variable */&lt;BR /&gt;
proc univariate data=eventdata noprint;&lt;BR /&gt;
  var eventduration;&lt;BR /&gt;
  output out=EventSummary n=N mode=Mode mean=Mean median=Median;&lt;BR /&gt;
run;&lt;BR /&gt;
proc print noobs; run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
result&lt;BR /&gt;
[pre]&lt;BR /&gt;
  N      Mean     Median    Mode&lt;BR /&gt;
1000    23.945      24       25&lt;BR /&gt;
[/pre]</description>
      <pubDate>Fri, 10 Jul 2009 14:08:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Calculating-average-time-duration/m-p/52986#M14608</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-07-10T14:08:04Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating average time (duration)</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Calculating-average-time-duration/m-p/52987#M14609</link>
      <description>Thank you, Scott and RichardK!  &lt;BR /&gt;
&lt;BR /&gt;
I was out Thursday and Friday and so just saw your responses this morning.  I am thrilled.  Both of you have given me something I think I can really work with to get the result I need.  As I mentioned, I'm a fairly new user to SAS so it may take me a bit to get all this to work for me but I am confident your suggestions will get me there.  If not, well, expect to see another post...&lt;BR /&gt;
&lt;BR /&gt;
Thanks again!</description>
      <pubDate>Mon, 13 Jul 2009 14:57:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Calculating-average-time-duration/m-p/52987#M14609</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-07-13T14:57:52Z</dc:date>
    </item>
  </channel>
</rss>

