<?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: One Record Per Hour of Day? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/One-Record-Per-Hour-of-Day/m-p/263041#M51473</link>
    <description>&lt;P&gt;Having done this analysis many times &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt; The next question is often day of week analysis by hour. Midnight on a Saturday&amp;nbsp;is different than midnight on a Wednesday because of availability/access to Primary Care Providers.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Radar charts actually show this type of data well by the way, because of the cyclical&amp;nbsp;nature of the data.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/graphref/63022/HTML/default/viewer.htm#a001572471.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/graphref/63022/HTML/default/viewer.htm#a001572471.htm&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 11 Apr 2016 22:10:25 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2016-04-11T22:10:25Z</dc:date>
    <item>
      <title>One Record Per Hour of Day?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/One-Record-Per-Hour-of-Day/m-p/262983#M51456</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am using SAS 9.3.&amp;nbsp; I have a data set where one row of data is one emergency department visit.&amp;nbsp; I would like to calculate number of patients in the ED during each hour of the visit.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I believe this is referred to as "occupancy" calculation and I've done it before when looking for daily rates, not hourly, for inpatient stays as per below:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set mydata;
do date=admitdate to disdate;
format date ddmmyy10.;
output;
end;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How would I do this hourly i.e. admitdatetime to dischdatetime but how do I specify only the hour i.e. if 13:30 then I want the hour to be 13?&amp;nbsp; Thanks.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Apr 2016 18:11:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/One-Record-Per-Hour-of-Day/m-p/262983#M51456</guid>
      <dc:creator>shellp55</dc:creator>
      <dc:date>2016-04-11T18:11:19Z</dc:date>
    </item>
    <item>
      <title>Re: One Record Per Hour of Day?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/One-Record-Per-Hour-of-Day/m-p/262993#M51457</link>
      <description>&lt;P&gt;You can use the hour() function to extract the hour.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your data is datetime, you're best bet is to round the data to the hour, you decide on up/down and then use a similar loop.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Because datetimes are the number of seconds since Jan 1, 1960 you can loop by an hour = 60 sec* 60 mins = 360&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Apr 2016 18:57:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/One-Record-Per-Hour-of-Day/m-p/262993#M51457</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-04-11T18:57:51Z</dc:date>
    </item>
    <item>
      <title>Re: One Record Per Hour of Day?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/One-Record-Per-Hour-of-Day/m-p/263024#M51466</link>
      <description>&lt;P&gt;See if this gives you a starting point:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data example;
   admitdate = '01JAN2016 12:23:40'dt;
   disdate = '02JAN2016 08:15:00'dt;
   format admitdate disdate datetime20.;
   Do Occupanthour = (dhms(datepart(admitdate),hour(admitdate),0,0)) to dhms(datepart(disdate),hour(disdate),0,0) by 3600;
      output;
   end;
   format OccupantHour datetime20.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It creates a new variable indicating the start hour for each hour in the interval.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suspect that you do not what to just look at time as admittance to discharge crossing the date boundary is common occurance.&lt;/P&gt;
&lt;P&gt;You could also use Hour(Occupanthour) to get&amp;nbsp; a single time of day with the hour for a report depending on your needs.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Apr 2016 20:32:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/One-Record-Per-Hour-of-Day/m-p/263024#M51466</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-04-11T20:32:41Z</dc:date>
    </item>
    <item>
      <title>Re: One Record Per Hour of Day?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/One-Record-Per-Hour-of-Day/m-p/263027#M51467</link>
      <description>&lt;P&gt;Thanks very much to both of you but I think Reeza's solution is the one I'm going with.&amp;nbsp; As for round up round down, since a patient with a registration time of 06:27 and a left ED time of 1130 hours would be in the ED at&amp;nbsp;0600,&amp;nbsp;0700, 0800, 0900, 1000, and 1100 I think it is safe to produce a record per hour.&amp;nbsp;Or do you see a downfall of that?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Apr 2016 20:43:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/One-Record-Per-Hour-of-Day/m-p/263027#M51467</guid>
      <dc:creator>shellp55</dc:creator>
      <dc:date>2016-04-11T20:43:40Z</dc:date>
    </item>
    <item>
      <title>Re: One Record Per Hour of Day?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/One-Record-Per-Hour-of-Day/m-p/263029#M51468</link>
      <description>&lt;P&gt;You need to use the full datetime value to account for patients in ER after midnight and before midnight appropriately. Especially if you're going to do analysis by day of week.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Apr 2016 20:49:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/One-Record-Per-Hour-of-Day/m-p/263029#M51468</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-04-11T20:49:06Z</dc:date>
    </item>
    <item>
      <title>Re: One Record Per Hour of Day?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/One-Record-Per-Hour-of-Day/m-p/263034#M51470</link>
      <description>&lt;P&gt;Hi Reeza&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks but I'm not understanding your comments.&amp;nbsp; What I was hoping to do was calculate volumes of ED patients by hour of day but not day itself.&amp;nbsp;&amp;nbsp; I would be interested in calculating before and after midnight as you suggested so can you please elaborate on what I have to do to for that to happen?&amp;nbsp; Thanks.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Apr 2016 21:01:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/One-Record-Per-Hour-of-Day/m-p/263034#M51470</guid>
      <dc:creator>shellp55</dc:creator>
      <dc:date>2016-04-11T21:01:29Z</dc:date>
    </item>
    <item>
      <title>Re: One Record Per Hour of Day?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/One-Record-Per-Hour-of-Day/m-p/263038#M51472</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza﻿&lt;/a&gt;&amp;nbsp;and my comments involve proper assignment of the times in the incrementing process. If you do not consider the day of the week what happens when you increment from 10 at night (hour 22) to 8 in the morning (hour 8). Ignoring the date change would require much work to get appropriate assignments.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is a sort of worked example creating fake data to two different forms of reports.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have (keep=admitdate disdate);
   /* generate some admission and discharge date time variables*/
   year=2015; /* for example all of the admits are in 2015*/
   format admitdate disdate datetime20.;
   do day= 1 to 20;
      do month=1 to 12;
         hour = floor(24*ranuni(4445));
         min  = floor(50*ranuni(1234));
         date = mdy(month,day,2015);
         admitdate=dhms(date,hour,min,0);
         /* random duration of stay*/
         duration = 60 + floor(3000*ranuni(7777));
         disdate = intnx('minute',admitdate,duration);
         output;
      end;
   end;
run;

data occupancy;
   set have;
   format admitdate disdate datetime20.;
   Do Occupanthour = (dhms(datepart(admitdate),hour(admitdate),0,0)) to dhms(datepart(disdate),hour(disdate),0,0) by 3600;
      HourOfDay = hour(OccupantHour);
      DayOfWeek = Weekday(datepart(OccupantHour));
      output;
   end;
   format OccupantHour datetime20.;
run;

Proc freq data=occupancy;
   Tables HourOfDay;
run;

proc tabulate data=occupancy;
   class DayOfWeek;
   class HourOfDay;
   tables HourOfDay,
          (DayOfWeek All)*n;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Since this is fake data do not expect the result to match your actual distributions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Apr 2016 21:37:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/One-Record-Per-Hour-of-Day/m-p/263038#M51472</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-04-11T21:37:59Z</dc:date>
    </item>
    <item>
      <title>Re: One Record Per Hour of Day?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/One-Record-Per-Hour-of-Day/m-p/263041#M51473</link>
      <description>&lt;P&gt;Having done this analysis many times &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt; The next question is often day of week analysis by hour. Midnight on a Saturday&amp;nbsp;is different than midnight on a Wednesday because of availability/access to Primary Care Providers.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Radar charts actually show this type of data well by the way, because of the cyclical&amp;nbsp;nature of the data.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/graphref/63022/HTML/default/viewer.htm#a001572471.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/graphref/63022/HTML/default/viewer.htm#a001572471.htm&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Apr 2016 22:10:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/One-Record-Per-Hour-of-Day/m-p/263041#M51473</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-04-11T22:10:25Z</dc:date>
    </item>
    <item>
      <title>Re: One Record Per Hour of Day?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/One-Record-Per-Hour-of-Day/m-p/263042#M51474</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw﻿&lt;/a&gt;&amp;nbsp;code is appropriate...&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www.health.alberta.ca/documents/PHC-Profile-EdmontonMillWoodsSouth-East.pdf" target="_blank"&gt;http://www.health.alberta.ca/documents/PHC-Profile-EdmontonMillWoodsSouth-East.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;See page 21 of the report here for what we did, though I'm not sure I would recommend that again. Monday at 1 am for example is highest for that hour, but that's really Sunday morning where finding a doctor or Urgent Care would be very difficult.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Apr 2016 22:15:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/One-Record-Per-Hour-of-Day/m-p/263042#M51474</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-04-11T22:15:38Z</dc:date>
    </item>
    <item>
      <title>Re: One Record Per Hour of Day?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/One-Record-Per-Hour-of-Day/m-p/263191#M51496</link>
      <description>&lt;P&gt;Thank you so much for the response, Reeza and &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/70517"&gt;@bballard﻿&lt;/a&gt;.&amp;nbsp; Nice work on the publication you shared.&amp;nbsp; The woman who is the head of the Alberta Health Authority used to be my Manager in Health Records!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Apr 2016 13:50:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/One-Record-Per-Hour-of-Day/m-p/263191#M51496</guid>
      <dc:creator>shellp55</dc:creator>
      <dc:date>2016-04-12T13:50:32Z</dc:date>
    </item>
    <item>
      <title>Re: One Record Per Hour of Day?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/One-Record-Per-Hour-of-Day/m-p/263705#M51621</link>
      <description>&lt;P&gt;Hello BallardW&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for the code on this but I'm confused by the "Have" dataset because the returned dates were not what was in my dataset.&amp;nbsp; For testing I extracted 1 day (April 1, 2015) of ED data.&amp;nbsp; Running the "Have" dataset and the result was cases that had admit dates beyond April 1, 2015.&amp;nbsp; Or should I just be running the occupancy portion?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Apr 2016 00:53:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/One-Record-Per-Hour-of-Day/m-p/263705#M51621</guid>
      <dc:creator>shellp55</dc:creator>
      <dc:date>2016-04-14T00:53:02Z</dc:date>
    </item>
    <item>
      <title>Re: One Record Per Hour of Day?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/One-Record-Per-Hour-of-Day/m-p/263717#M51625</link>
      <description>&lt;P&gt;ER stays have been known to go up to 36 hours so you could go to April 2 for occupancy.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Apr 2016 01:27:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/One-Record-Per-Hour-of-Day/m-p/263717#M51625</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-04-14T01:27:39Z</dc:date>
    </item>
  </channel>
</rss>

