<?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: Aggregate rows based on groups in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Aggregate-rows-based-on-groups/m-p/580514#M13567</link>
    <description>&lt;P&gt;FWIW&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input Column1 $ Column2;
datalines;
A 500
B 580
A 911
B 419
B 165
;
data _null_;
if _n_=1 then do;
   dcl hash H () ;
   h.definekey  ("Column1") ;
   h.definedata ("Column1","sum") ;
   h.definedone () ;
end;
do until(z);
 set have end=z;
 if h.find()= 0 then sum=sum(sum,column2);
 else sum=column2;
 h.replace();
end;
h.output(dataset:'want');
stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 12 Aug 2019 11:55:24 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2019-08-12T11:55:24Z</dc:date>
    <item>
      <title>Aggregate rows based on groups</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Aggregate-rows-based-on-groups/m-p/580495#M13559</link>
      <description>&lt;P&gt;Hello SAS Community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm doing my first steps in SAS at the moment and i've gote a problem which i can't solve...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a table like the following example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Column1 - Column2&lt;/P&gt;&lt;P&gt;A&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; - 500&lt;/P&gt;&lt;P&gt;B&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; - 580&lt;/P&gt;&lt;P&gt;A&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; - 911&lt;/P&gt;&lt;P&gt;B&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; - 419&lt;/P&gt;&lt;P&gt;B&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; - 165&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So all i want to do is to create a new SAS Table with aggregated rows for all "A"s and "B"s.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Aug 2019 09:25:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Aggregate-rows-based-on-groups/m-p/580495#M13559</guid>
      <dc:creator>Lars45</dc:creator>
      <dc:date>2019-08-12T09:25:41Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregate rows based on groups</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Aggregate-rows-based-on-groups/m-p/580499#M13561</link>
      <description>&lt;P&gt;Welcome to the SAS Community &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is this what you are after?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Column1 $ Column2;
datalines;
A 500
B 580
A 911
B 419
B 165
;

proc sql;
    create table want as
    select Column1, sum(Column2) as sum
    from have
    group by Column1;
quit; &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 12 Aug 2019 09:33:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Aggregate-rows-based-on-groups/m-p/580499#M13561</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-08-12T09:33:29Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregate rows based on groups</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Aggregate-rows-based-on-groups/m-p/580503#M13563</link>
      <description>Thanks for the quick answer!&lt;BR /&gt;This might be a solutions, but I was actually looking for a way without writing code myself.&lt;BR /&gt;I should have been more specific....&lt;BR /&gt;I will try to use your solution, but with that one I have to figure out some more things before I can tell if it works.&lt;BR /&gt;</description>
      <pubDate>Mon, 12 Aug 2019 09:44:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Aggregate-rows-based-on-groups/m-p/580503#M13563</guid>
      <dc:creator>Lars45</dc:creator>
      <dc:date>2019-08-12T09:44:43Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregate rows based on groups</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Aggregate-rows-based-on-groups/m-p/580505#M13564</link>
      <description>&lt;P&gt;Alternatively via data step&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Column1$ Column2;
cards;
A 500
B 580
A 911
B 419
B 165
;

proc sort data=have;
by column1;
run;

data want;
set have;
by column1;
retain sum;
if first.column1 then sum=column2;
else sum+column2;
if last.column1;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 12 Aug 2019 09:57:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Aggregate-rows-based-on-groups/m-p/580505#M13564</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2019-08-12T09:57:48Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregate rows based on groups</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Aggregate-rows-based-on-groups/m-p/580514#M13567</link>
      <description>&lt;P&gt;FWIW&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input Column1 $ Column2;
datalines;
A 500
B 580
A 911
B 419
B 165
;
data _null_;
if _n_=1 then do;
   dcl hash H () ;
   h.definekey  ("Column1") ;
   h.definedata ("Column1","sum") ;
   h.definedone () ;
end;
do until(z);
 set have end=z;
 if h.find()= 0 then sum=sum(sum,column2);
 else sum=column2;
 h.replace();
end;
h.output(dataset:'want');
stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 12 Aug 2019 11:55:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Aggregate-rows-based-on-groups/m-p/580514#M13567</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-08-12T11:55:24Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregate rows based on groups</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Aggregate-rows-based-on-groups/m-p/580518#M13568</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=have nway ;
class column1;
var column2;
output out=want(drop=_:) sum=sum;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 12 Aug 2019 12:02:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Aggregate-rows-based-on-groups/m-p/580518#M13568</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-08-12T12:02:54Z</dc:date>
    </item>
  </channel>
</rss>

