<?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: Average Patients Per Day in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Average-Patients-Per-Day/m-p/675062#M203341</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/25335"&gt;@sjarvis847&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks for your reply!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I just tried this and it gave me an error that there is an invalid DO loop, either the initial or TO expression is missing or the by expression is missing, zero or invalid.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Then you must have made a mistake copying the code. See this example with some made-up data:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data cov;
input arrdate:yymmdd10. mrn $;
format arrdate yymmdd10.;
datalines;
2020-08-01 A
2020-08-01 B
2020-08-01 C
2020-08-02 A
2020-08-02 B
2020-08-05 D
2020-08-05 E
2020-08-05 F
;

proc sql;
create table new as
select arrdate, count (mrn) as patients
from cov
group by arrdate;
quit;

data complete;
merge
  new
  new (firstobs=2 keep=arrdate rename=(arrdate=_arrdate))
;
output;
patients = 0;
do arrdate = arrdate + 1 to _arrdate - 1;
  output;
end;
drop _arrdate;
run;

proc sql;
create table average as
select month(arrdate) as month, day(arrdate) as day, avg (patients)
from complete
group by month, day;
quit;

proc print data=complete noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;arrdate	patients
2020-08-01	3
2020-08-02	2
2020-08-03	0
2020-08-04	0
2020-08-05	3
&lt;/PRE&gt;
&lt;P&gt;Please post the log of your failed code; use this button to post the log:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Bildschirmfoto 2020-04-07 um 08.32.59.jpg"&gt;&lt;img src="https://communities.sas.com/skins/images/2FD96521DCF95C42FE57BF2A7CB72678/responsive_peak/images/image_not_found.png" alt="Bildschirmfoto 2020-04-07 um 08.32.59.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 06 Aug 2020 16:27:02 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-08-06T16:27:02Z</dc:date>
    <item>
      <title>Average Patients Per Day</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Average-Patients-Per-Day/m-p/675033#M203323</link>
      <description>&lt;P&gt;Hello all!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I used the following code to create a database which had the number of patients enrolled per day, that way I could compare the average patients per day during each enrollment period. However it's not accounting for the days with 0 patients enrolled. Anyone have an idea on how to add rows for days with 0 patients?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table strcovid.new as&lt;BR /&gt;select arrdate, count (mrn) as patients&lt;BR /&gt;from strcovid.cov&lt;BR /&gt;group by arrdate;&lt;/P&gt;&lt;P&gt;create table average as&lt;BR /&gt;select month(arrdate) as month, day(arrdate) as day, avg (patients)&lt;BR /&gt;from strcovid.new&lt;BR /&gt;group by month, day;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&amp;nbsp;&lt;/P&gt;&lt;P&gt;Stephanie&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Aug 2020 15:32:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Average-Patients-Per-Day/m-p/675033#M203323</guid>
      <dc:creator>sjarvis847</dc:creator>
      <dc:date>2020-08-06T15:32:34Z</dc:date>
    </item>
    <item>
      <title>Re: Average Patients Per Day</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Average-Patients-Per-Day/m-p/675034#M203324</link>
      <description>You need to ensure you have a record for every day or do a custom calculation for the average where you specify the denominator. &lt;BR /&gt;Is this over a fixed period each time?</description>
      <pubDate>Thu, 06 Aug 2020 15:36:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Average-Patients-Per-Day/m-p/675034#M203324</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-08-06T15:36:45Z</dc:date>
    </item>
    <item>
      <title>Re: Average Patients Per Day</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Average-Patients-Per-Day/m-p/675035#M203325</link>
      <description>&lt;P&gt;Insert a data step with a look-ahead that adds the missing days:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table strcovid.new as
select arrdate, count (mrn) as patients
from strcovid.cov
group by arrdate;
quit;

data strcovid.complete;
merge
  strcovid.new
  strcovid.new (firstobs=2 keep=arrdate rename=(arrdate=_arrdate))
;
output;
patients = 0;
do arrdate = arrdate + 1 to _arrdate - 1;
  output;
end;
drop _arrdate;
run;

proc sql;
create table average as
select month(arrdate) as month, day(arrdate) as day, avg (patients)
from strcovid.complete
group by month, day;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 06 Aug 2020 15:38:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Average-Patients-Per-Day/m-p/675035#M203325</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-08-06T15:38:46Z</dc:date>
    </item>
    <item>
      <title>Re: Average Patients Per Day</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Average-Patients-Per-Day/m-p/675036#M203326</link>
      <description>&lt;P&gt;You could determine how many days in a month, this is a known fact. You compute the sum of patients enrolled in a month (this is the numerator of the mean enrollments per month) and then divide by the number of days in the month (the denominator) to give you the mean enrollments per day in that month.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Aug 2020 15:45:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Average-Patients-Per-Day/m-p/675036#M203326</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-08-06T15:45:57Z</dc:date>
    </item>
    <item>
      <title>Re: Average Patients Per Day</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Average-Patients-Per-Day/m-p/675041#M203328</link>
      <description>&lt;P&gt;Your code is currently operating at a daily level so your average will always be the same as the daily value. What are you really trying to do here overall? Get the average # of days over the month into your data set?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/25335"&gt;@sjarvis847&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello all!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I used the following code to create a database which had the number of patients enrolled per day, that way I could compare the average patients per day during each enrollment period. However it's not accounting for the days with 0 patients enrolled. Anyone have an idea on how to add rows for days with 0 patients?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table strcovid.new as&lt;BR /&gt;select arrdate, count (mrn) as patients&lt;BR /&gt;from strcovid.cov&lt;BR /&gt;&lt;STRONG&gt;group by arrdate;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;create table average as&lt;BR /&gt;select month(arrdate) as month, day(arrdate) as day, avg (patients)&lt;BR /&gt;from strcovid.new&lt;BR /&gt;&lt;STRONG&gt;group by month, day;&lt;/STRONG&gt;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Stephanie&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Aug 2020 15:58:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Average-Patients-Per-Day/m-p/675041#M203328</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-08-06T15:58:51Z</dc:date>
    </item>
    <item>
      <title>Re: Average Patients Per Day</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Average-Patients-Per-Day/m-p/675044#M203330</link>
      <description>&lt;P&gt;Thanks for your reply!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just tried this and it gave me an error that there is an invalid DO loop, either the initial or TO expression is missing or the by expression is missing, zero or invalid.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Aug 2020 16:02:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Average-Patients-Per-Day/m-p/675044#M203330</guid>
      <dc:creator>sjarvis847</dc:creator>
      <dc:date>2020-08-06T16:02:05Z</dc:date>
    </item>
    <item>
      <title>Re: Average Patients Per Day</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Average-Patients-Per-Day/m-p/675046#M203331</link>
      <description>&lt;P&gt;Hi Paige,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your reply. I am hoping to look at patients/ day not per month &amp;amp; eventually want to use statistical methods to compare the patients per day enrolled per group. I know how to calculate an average by hand. I need it in sas so I can determine the p-value when I compare. Thanks for the suggestion though!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Steph&lt;/P&gt;</description>
      <pubDate>Thu, 06 Aug 2020 16:03:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Average-Patients-Per-Day/m-p/675046#M203331</guid>
      <dc:creator>sjarvis847</dc:creator>
      <dc:date>2020-08-06T16:03:41Z</dc:date>
    </item>
    <item>
      <title>Re: Average Patients Per Day</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Average-Patients-Per-Day/m-p/675048#M203333</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/25335"&gt;@sjarvis847&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi Paige,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for your reply. I am hoping to look at patients/ day not per month &amp;amp; eventually want to use statistical methods to compare the patients per day enrolled per group. I know how to calculate an average by hand. I need it in sas so I can determine the p-value when I compare. Thanks for the suggestion though!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Steph&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I'm afraid I don't understand. Your code will compute average per day, which is the same as the number of patients in a day. The averaging does nothing.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Aug 2020 16:08:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Average-Patients-Per-Day/m-p/675048#M203333</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-08-06T16:08:37Z</dc:date>
    </item>
    <item>
      <title>Re: Average Patients Per Day</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Average-Patients-Per-Day/m-p/675051#M203335</link>
      <description>&lt;P&gt;Hi Reeza,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your reply!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes it is operating at the daily level and is currently providing the accurate number of patients enrolled per day, &lt;EM&gt;except&lt;/EM&gt; for days when no patients are enrolled. The values are not the same for each day. For example, 4/1/2018 4 patients were enrolled, 4/2/2018 1 patient was enrolled, 4/8/2018 no patients were enrolled but currently there exists no value for 4/8/2018 in the dataset for 4/82018 as it's only count days with patients enrolled.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The goal is get a dataset with number of patients per day.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then assign the groups using enrollment date.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Check normality of data, determine median or mean patients per day for each group. Use proper statistics to compare the mean or median patients per day in each group.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Without the 0 values entered I won't have the true average number of patients per day, I will have the average number of patients enrolled per day for days which enrollment occured if that makes sense (which is not what I want).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We are comparing admission of patients before and after COVID, assumption that COVID resulted in fewer admissions/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again for your help!!!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Stephanie&lt;/P&gt;</description>
      <pubDate>Thu, 06 Aug 2020 16:10:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Average-Patients-Per-Day/m-p/675051#M203335</guid>
      <dc:creator>sjarvis847</dc:creator>
      <dc:date>2020-08-06T16:10:18Z</dc:date>
    </item>
    <item>
      <title>Re: Average Patients Per Day</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Average-Patients-Per-Day/m-p/675052#M203336</link>
      <description>&lt;P&gt;Hi Paige,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code creates the number of patients enrolled per day. Then I take the average and compare if the average number of patients per day changed during the enrollment periods. Currently there is a difference observed in the average number of patients enrolled per day (in 2019 = 4 patients came in per day, during COVID = 2 patients came in per day). However because the days with 0 patients per day don't exist, the difference could be even greater that what I previously wrote.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As there are not statistical tools to compare raw counts (I have the total volume [#] of patients during each enrollment period), I am comparing the number of patients who came in by day. I am sorry to hear this doesn't make sense to you.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks anyway,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Steph&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Steph&lt;/P&gt;</description>
      <pubDate>Thu, 06 Aug 2020 16:16:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Average-Patients-Per-Day/m-p/675052#M203336</guid>
      <dc:creator>sjarvis847</dc:creator>
      <dc:date>2020-08-06T16:16:05Z</dc:date>
    </item>
    <item>
      <title>Re: Average Patients Per Day</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Average-Patients-Per-Day/m-p/675057#M203338</link>
      <description>&lt;P&gt;Yes, we are comparing during COVID this year, to same period in 2019 and same period in 2018. There exists no rows for dates without a patient enrolled which is why those dates don't have a value....&lt;/P&gt;</description>
      <pubDate>Thu, 06 Aug 2020 16:17:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Average-Patients-Per-Day/m-p/675057#M203338</guid>
      <dc:creator>sjarvis847</dc:creator>
      <dc:date>2020-08-06T16:17:57Z</dc:date>
    </item>
    <item>
      <title>Re: Average Patients Per Day</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Average-Patients-Per-Day/m-p/675059#M203340</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;The code creates the number of patients enrolled per day.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If there are 80 patients enrolled on a given day, it creates an average of 80. Why do this?&lt;/P&gt;</description>
      <pubDate>Thu, 06 Aug 2020 18:21:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Average-Patients-Per-Day/m-p/675059#M203340</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-08-06T18:21:59Z</dc:date>
    </item>
    <item>
      <title>Re: Average Patients Per Day</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Average-Patients-Per-Day/m-p/675062#M203341</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/25335"&gt;@sjarvis847&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks for your reply!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I just tried this and it gave me an error that there is an invalid DO loop, either the initial or TO expression is missing or the by expression is missing, zero or invalid.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Then you must have made a mistake copying the code. See this example with some made-up data:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data cov;
input arrdate:yymmdd10. mrn $;
format arrdate yymmdd10.;
datalines;
2020-08-01 A
2020-08-01 B
2020-08-01 C
2020-08-02 A
2020-08-02 B
2020-08-05 D
2020-08-05 E
2020-08-05 F
;

proc sql;
create table new as
select arrdate, count (mrn) as patients
from cov
group by arrdate;
quit;

data complete;
merge
  new
  new (firstobs=2 keep=arrdate rename=(arrdate=_arrdate))
;
output;
patients = 0;
do arrdate = arrdate + 1 to _arrdate - 1;
  output;
end;
drop _arrdate;
run;

proc sql;
create table average as
select month(arrdate) as month, day(arrdate) as day, avg (patients)
from complete
group by month, day;
quit;

proc print data=complete noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;arrdate	patients
2020-08-01	3
2020-08-02	2
2020-08-03	0
2020-08-04	0
2020-08-05	3
&lt;/PRE&gt;
&lt;P&gt;Please post the log of your failed code; use this button to post the log:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Bildschirmfoto 2020-04-07 um 08.32.59.jpg"&gt;&lt;img src="https://communities.sas.com/skins/images/2FD96521DCF95C42FE57BF2A7CB72678/responsive_peak/images/image_not_found.png" alt="Bildschirmfoto 2020-04-07 um 08.32.59.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Aug 2020 16:27:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Average-Patients-Per-Day/m-p/675062#M203341</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-08-06T16:27:02Z</dc:date>
    </item>
  </channel>
</rss>

