<?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: Counting admitted patients (Length of Stay) by day - Array/do loops in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Counting-admitted-patients-Length-of-Stay-by-day-Array-do-loops/m-p/554089#M9451</link>
    <description>Also works, PG. Thank you so much for your input. You guys are great!&lt;BR /&gt;&lt;BR /&gt;Alex</description>
    <pubDate>Thu, 25 Apr 2019 21:08:18 GMT</pubDate>
    <dc:creator>avbraga</dc:creator>
    <dc:date>2019-04-25T21:08:18Z</dc:date>
    <item>
      <title>Counting admitted patients (Length of Stay) by day - Array/do loops</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Counting-admitted-patients-Length-of-Stay-by-day-Array-do-loops/m-p/554073#M9446</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to count, by day, how many people are in a hospital, given the fact that I have the patient’s admission date (start_date), discharge date (end_date), and their length of stay.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Visually this is what I am looking for, the cells in yellow populated, so they can then be summarized by day.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="calendar.JPG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/29051i038C14F5D49B939D/image-size/large?v=v2&amp;amp;px=999" role="button" title="calendar.JPG" alt="calendar.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Programmatically what I was thinking was:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;have SAS create as many new "month_day" columns based on the min(start_date) and max(discharge_date). Those are represented in the attached picture as columns April_07, April_08, April_09, etc.&lt;/LI&gt;
&lt;LI&gt;in a array/do loop of sorts, have sas look up the month and day of the start_date and of the end_date, and map those to the "month_day" columns with prefixes that match the start and end date.&lt;/LI&gt;
&lt;LI&gt;Put a “1” on those columns so they can later be summarized by day.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I attempted a code that was something like the below, which doesn’t work, because each row will have a different “i” subscript range.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;array days(*) april_07-april_20;&lt;/P&gt;
&lt;P&gt;do i = begin_day to end_day;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if days(i) = &lt;STRONG&gt;0&lt;/STRONG&gt; then days(i) = &lt;STRONG&gt;1&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;drop i;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;******&lt;/P&gt;
&lt;P&gt;Any way I can do the above programmatically? Any other ways that i am not seeing that can do this task programmatically?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your help is appreciated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Alex&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Apr 2019 20:15:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Counting-admitted-patients-Length-of-Stay-by-day-Array-do-loops/m-p/554073#M9446</guid>
      <dc:creator>avbraga</dc:creator>
      <dc:date>2019-04-25T20:15:52Z</dc:date>
    </item>
    <item>
      <title>Re: Counting admitted patients (Length of Stay) by day - Array/do loops</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Counting-admitted-patients-Length-of-Stay-by-day-Array-do-loops/m-p/554079#M9448</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/2685"&gt;@avbraga&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to count, by day, how many people are in a hospital, given the fact that I have the patient’s admission date (start_date), discharge date (end_date), and their length of stay.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Visually this is what I am looking for, the cells in yellow populated, so they can then be summarized by day.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="calendar.JPG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/29051i038C14F5D49B939D/image-size/large?v=v2&amp;amp;px=999" role="button" title="calendar.JPG" alt="calendar.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Programmatically what I was thinking was:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;have SAS create as many new "month_day" columns based on the min(start_date) and max(discharge_date). Those are represented in the attached picture as columns April_07, April_08, April_09, etc.&lt;/LI&gt;
&lt;LI&gt;in a array/do loop of sorts, have sas look up the month and day of the start_date and of the end_date, and map those to the "month_day" columns with prefixes that match the start and end date.&lt;/LI&gt;
&lt;LI&gt;Put a “1” on those columns so they can later be summarized by day.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I attempted a code that was something like the below, which doesn’t work, because each row will have a different “i” subscript range.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;array days(*) april_07-april_20;&lt;/P&gt;
&lt;P&gt;do i = begin_day to end_day;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if days(i) = &lt;STRONG&gt;0&lt;/STRONG&gt; then days(i) = &lt;STRONG&gt;1&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;drop i;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;******&lt;/P&gt;
&lt;P&gt;Any way I can do the above programmatically? Any other ways that i am not seeing that can do this task programmatically?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your help is appreciated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Alex&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you are looking to sum things by date across patients then you do NOT want to add that many columns.&lt;/P&gt;
&lt;P&gt;Consider:&lt;/P&gt;
&lt;PRE&gt;data example;
   input patientid $ begin_day : date9. end_day :date9.;
   format begin_day end_day date9.;
datalines ;
11111  01Jan2019 14Jan2019
2222   12Jan2019 15Jan2019
333    10Jan2019 12Jan2019
;
run;

data want;
   set example;
   do activedate = begin_day to end_day;
      output;
   end;
   format activedate date9.;
   label activedate = 'Day in hosptital';
run;

/* to get a data set with count of patients per calendar day*/
proc summary data=want nway;
   class activedate;
   output out=work.daycount (drop=_type_);
run;

&lt;/PRE&gt;
&lt;P&gt;The output creates one record for each date in the hospital.&lt;/P&gt;
&lt;P&gt;If your begin and end dates are currently not SAS date values then that is the first step: make sure you have dates.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to display the data, or a subset, in a wide format then something like:&lt;/P&gt;
&lt;PRE&gt;Proc tabulate data=want;
   class patientid activedate;
   table patientid,
         activedate=' '*n=' '
         /misstext='0'
   ;
run;
&lt;/PRE&gt;
&lt;P&gt;Other variables would be carried along in the WANT data set so you could get summaries by any likely grouping you need.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Apr 2019 20:48:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Counting-admitted-patients-Length-of-Stay-by-day-Array-do-loops/m-p/554079#M9448</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-04-25T20:48:51Z</dc:date>
    </item>
    <item>
      <title>Re: Counting admitted patients (Length of Stay) by day - Array/do loops</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Counting-admitted-patients-Length-of-Stay-by-day-Array-do-loops/m-p/554083#M9449</link>
      <description>&lt;P&gt;Hi ballardw,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is a thing of beauty. Exactly what I needed without the convolution. Simple and elegant.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you so much!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Alex&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Apr 2019 20:52:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Counting-admitted-patients-Length-of-Stay-by-day-Array-do-loops/m-p/554083#M9449</guid>
      <dc:creator>avbraga</dc:creator>
      <dc:date>2019-04-25T20:52:45Z</dc:date>
    </item>
    <item>
      <title>Re: Counting admitted patients (Length of Stay) by day - Array/do loops</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Counting-admitted-patients-Length-of-Stay-by-day-Array-do-loops/m-p/554086#M9450</link>
      <description>&lt;P&gt;Expand and count:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data stays;
input hosp $ patientID date_begin:date9. date_end:date9.;
datalines;
A 1 20jan2001 15mar2001
A 2 22jan2001 15feb2001
A 3 10jan2001 10mar2001
;

data days;
set stays;
do day = date_begin to date_end;
    output;
    end;
format day yymmdd10.;
keep hosp day;
run;

proc sql;
create table hospPop as
select hosp, day, count(*) as nbPatients
from days
group by hosp, day;
quit;

proc print data=hospPop noobs; run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 25 Apr 2019 21:03:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Counting-admitted-patients-Length-of-Stay-by-day-Array-do-loops/m-p/554086#M9450</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-04-25T21:03:22Z</dc:date>
    </item>
    <item>
      <title>Re: Counting admitted patients (Length of Stay) by day - Array/do loops</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Counting-admitted-patients-Length-of-Stay-by-day-Array-do-loops/m-p/554089#M9451</link>
      <description>Also works, PG. Thank you so much for your input. You guys are great!&lt;BR /&gt;&lt;BR /&gt;Alex</description>
      <pubDate>Thu, 25 Apr 2019 21:08:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Counting-admitted-patients-Length-of-Stay-by-day-Array-do-loops/m-p/554089#M9451</guid>
      <dc:creator>avbraga</dc:creator>
      <dc:date>2019-04-25T21:08:18Z</dc:date>
    </item>
  </channel>
</rss>

