<?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: Accumulating Variables in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Accumulating-Variables/m-p/607670#M17582</link>
    <description>Thanks!</description>
    <pubDate>Wed, 27 Nov 2019 13:15:20 GMT</pubDate>
    <dc:creator>K_Wils15</dc:creator>
    <dc:date>2019-11-27T13:15:20Z</dc:date>
    <item>
      <title>Accumulating Variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Accumulating-Variables/m-p/607661#M17577</link>
      <description>&lt;P&gt;Hi everyone, I am stuck on this problem:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Using RETAIN, FIRST./LAST. and accumulating variables, find the total number of days each patient spent in hospital – not per episode but overall per patient; also count the number of hospital episodes for each patient.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The number of days for each episode (observation) is found by DISCDATE_DT – ADMIDATE_DT + 1.&amp;nbsp; Then use PROC MEANS to find the maximum and the average number of total hospital days per patient, and the maximum and average number of hospital episodes per patient.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my log with the code I have so far. I am not sure why there are errors or how to fix them:&lt;/P&gt;&lt;P&gt;380 data hosp_adm3;&lt;BR /&gt;381 set hosp_adm2;&lt;BR /&gt;382 by pt_id;&lt;BR /&gt;383 retain prior_disc sum_days count;&lt;BR /&gt;384&lt;BR /&gt;385 if first.pt.id = 1 then do;&lt;BR /&gt;386 count = 0;&lt;BR /&gt;387 sum_days = 0;&lt;BR /&gt;388 end;&lt;BR /&gt;389 los = discdate_dt - admndate_dt + 1;&lt;BR /&gt;390 sum_days + los;&lt;BR /&gt;391 *same as sum = sum(sum, los);&lt;BR /&gt;392 count + 1;&lt;BR /&gt;393 output hosp_adm3 (drop = sum_days count);&lt;BR /&gt;-&lt;BR /&gt;22&lt;BR /&gt;76&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 0.00 seconds&lt;BR /&gt;cpu time 0.01 seconds&lt;/P&gt;&lt;P&gt;FATAL: DATA STEP compilation stopped due to syntax errors.&lt;BR /&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, ;, RC,&lt;BR /&gt;_DATA_, _LAST_, _NULL_.&lt;/P&gt;&lt;P&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/P&gt;&lt;P&gt;394&lt;BR /&gt;395 if last.pt_id = 1 then output hosp_adm4 (keep = pt_id sum count);&lt;BR /&gt;-&lt;BR /&gt;22&lt;BR /&gt;76&lt;BR /&gt;ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, ;, RC,&lt;BR /&gt;_DATA_, _LAST_, _NULL_.&lt;/P&gt;&lt;P&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/P&gt;&lt;P&gt;396&lt;BR /&gt;397 if first.pt_id = 0 then day_com = admidate_dt - prior_disc;&lt;BR /&gt;398 prior_disc = discodate_dt;&lt;BR /&gt;399 run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Nov 2019 12:52:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Accumulating-Variables/m-p/607661#M17577</guid>
      <dc:creator>K_Wils15</dc:creator>
      <dc:date>2019-11-27T12:52:23Z</dc:date>
    </item>
    <item>
      <title>Re: Accumulating Variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Accumulating-Variables/m-p/607663#M17578</link>
      <description>&lt;P&gt;&lt;FONT color="#FF0000"&gt;&lt;SPAN&gt;393 output hosp_adm3 (drop = sum_days count);&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;&lt;SPAN&gt;-&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;&lt;SPAN&gt;22&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;&lt;SPAN&gt;76&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;You can't use data set options like DROP= in the OUTPUT statement (as far as I know).&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to create two output data sets, then both must be mentioned in the DATA statement, and then you can do something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data hosp_adm3(drop=sum_days count) hosp_adm4(keep=pt_id sum count);
... programming statements ...
output hosp_adm3;
if last.pt_id then output hosp_adm4;
... more programming statements if desired ...
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Nov 2019 13:06:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Accumulating-Variables/m-p/607663#M17578</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-11-27T13:06:34Z</dc:date>
    </item>
    <item>
      <title>Re: Accumulating Variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Accumulating-Variables/m-p/607665#M17579</link>
      <description>&lt;P&gt;Dataset options cannot be used in an output statement. Use them in the data statement instead.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Nov 2019 13:02:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Accumulating-Variables/m-p/607665#M17579</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-11-27T13:02:14Z</dc:date>
    </item>
    <item>
      <title>Re: Accumulating Variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Accumulating-Variables/m-p/607666#M17580</link>
      <description>&lt;P&gt;Essentially, the output data set options to &lt;FONT face="courier new,courier"&gt;keep&lt;/FONT&gt; or &lt;FONT face="courier new,courier"&gt;drop&lt;/FONT&gt; variables should be part of the &lt;FONT face="courier new,courier"&gt;data&lt;/FONT&gt; statement and you should specify all output data sets on the &lt;FONT face="courier new,courier"&gt;data&lt;/FONT&gt; statement. For example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data hosp_adm3(drop = sum_days count)
     hosp_adm4(keep = pt_id sum count)
     ;
   set hosp_adm2;
   by pt_id;
   retain prior_disc sum_days count;

   if first.pt.id = 1 then
   do;
      count = 0;
      sum_days = 0;
   end;

   los = discdate_dt - admndate_dt + 1;
   sum_days + los;
   *same as sum = sum(sum, los);
   count + 1;
   output hosp_adm3;

   if last.pt_id = 1 then
      output hosp_adm4;

   if first.pt_id = 0 then
      day_com = admidate_dt - prior_disc;

   prior_disc = discodate_dt;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;Amir.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Nov 2019 13:02:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Accumulating-Variables/m-p/607666#M17580</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2019-11-27T13:02:44Z</dc:date>
    </item>
    <item>
      <title>Re: Accumulating Variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Accumulating-Variables/m-p/607670#M17582</link>
      <description>Thanks!</description>
      <pubDate>Wed, 27 Nov 2019 13:15:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Accumulating-Variables/m-p/607670#M17582</guid>
      <dc:creator>K_Wils15</dc:creator>
      <dc:date>2019-11-27T13:15:20Z</dc:date>
    </item>
  </channel>
</rss>

