<?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: GROUP BY in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/GROUP-BY/m-p/803186#M81672</link>
    <description>&lt;P&gt;Use BY in the data step and the first. and last. automatic variables:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=resul_perf;
by date;
run;

data resul1_perf;
set resul_perf;
by date;
retain bad_acc good_acc;
if first.date
then do;
  bad_acc = bad;
  good_acc = good;
end;
else do;
  bad_acc = bad_acc + bad;
  good_acc = good_acc + good;
end;
if last.date;
dif_acc = abs(bad_acc - good_acc);
format
  bad_acc
  good_acc
  dif_acc commax20.3
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 21 Mar 2022 17:51:27 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2022-03-21T17:51:27Z</dc:date>
    <item>
      <title>GROUP BY</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/GROUP-BY/m-p/803182#M81670</link>
      <description>&lt;P&gt;I have the following code, which is returning the accumulated sum of all observations. But I want the accumulated sum by date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In "proc sql" would do:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;group by date&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But in this code that I have, what do I do?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data resul1_perf;&lt;/P&gt;
&lt;P&gt;set resul_perf;&lt;/P&gt;
&lt;P&gt;retain bad_acc good_acc;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="4"&gt;if _n_ = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="4" color="#08726d"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="4"&gt; then bad_acc = bad;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;else bad_acc = bad_acc + bad;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="4"&gt;if _n_ = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="4" color="#08726d"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="4"&gt; then good_acc = good;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;else good_acc = good_acc + good;&lt;/P&gt;
&lt;P&gt;dif_acc = abs(bad_acc - good_acc);&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="4"&gt;FORMAT bad_acc &lt;/FONT&gt;&lt;FONT face="Courier New" size="4" color="#08726d"&gt;COMMAX20.3&lt;/FONT&gt;&lt;FONT face="Courier New" size="4"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="4"&gt;FORMAT good_acc &lt;/FONT&gt;&lt;FONT face="Courier New" size="4" color="#08726d"&gt;COMMAX20.3&lt;/FONT&gt;&lt;FONT face="Courier New" size="4"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="4"&gt;FORMAT dif_acc &lt;/FONT&gt;&lt;FONT face="Courier New" size="4" color="#08726d"&gt;COMMAX20.3&lt;/FONT&gt;&lt;FONT face="Courier New" size="4"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Mar 2022 17:43:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/GROUP-BY/m-p/803182#M81670</guid>
      <dc:creator>Thalitacosta</dc:creator>
      <dc:date>2022-03-21T17:43:17Z</dc:date>
    </item>
    <item>
      <title>Re: GROUP BY</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/GROUP-BY/m-p/803184#M81671</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data resul1_perf;
    set resul_perf;
    by date;
    if first.date then do;
        bad_acc=0;
        good_acc=0;
    end;
    bad_acc + bad;
    good_acc + good;
    dif_acc = abs(bad_acc - good_acc);
    FORMAT bad_acc good_acc dif_acc COMMAX20.3;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 21 Mar 2022 17:48:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/GROUP-BY/m-p/803184#M81671</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-03-21T17:48:04Z</dc:date>
    </item>
    <item>
      <title>Re: GROUP BY</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/GROUP-BY/m-p/803186#M81672</link>
      <description>&lt;P&gt;Use BY in the data step and the first. and last. automatic variables:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=resul_perf;
by date;
run;

data resul1_perf;
set resul_perf;
by date;
retain bad_acc good_acc;
if first.date
then do;
  bad_acc = bad;
  good_acc = good;
end;
else do;
  bad_acc = bad_acc + bad;
  good_acc = good_acc + good;
end;
if last.date;
dif_acc = abs(bad_acc - good_acc);
format
  bad_acc
  good_acc
  dif_acc commax20.3
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 21 Mar 2022 17:51:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/GROUP-BY/m-p/803186#M81672</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-03-21T17:51:27Z</dc:date>
    </item>
  </channel>
</rss>

