<?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 What is the most efficient way to add down per column per group? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/What-is-the-most-efficient-way-to-add-down-per-column-per-group/m-p/843481#M333468</link>
    <description>&lt;P&gt;Hello, I'm trying to add down the column per group and merge that total back into the original data set. What is the most efficient way to do this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;Note: The variable MAINCAT contains the groups that i need the totals for.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines dsd dlm=",";
	input maincat $ subcat $ count1;
datalines;
Red, Red1, 32
Red, Red2, 17
Red, Red3, 7
Orange, Orange1, 22
Orange, Orange2, 11
Orange, Orange3, 6
Yellow, Yellow1, 14
Yellow, Yellow2, 12
;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This is the desired output:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Hello_there_0-1668031110801.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/77136i1F3A01DCF0776BDD/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Hello_there_0-1668031110801.png" alt="Hello_there_0-1668031110801.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 09 Nov 2022 21:59:05 GMT</pubDate>
    <dc:creator>Hello_there</dc:creator>
    <dc:date>2022-11-09T21:59:05Z</dc:date>
    <item>
      <title>What is the most efficient way to add down per column per group?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-the-most-efficient-way-to-add-down-per-column-per-group/m-p/843481#M333468</link>
      <description>&lt;P&gt;Hello, I'm trying to add down the column per group and merge that total back into the original data set. What is the most efficient way to do this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;Note: The variable MAINCAT contains the groups that i need the totals for.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines dsd dlm=",";
	input maincat $ subcat $ count1;
datalines;
Red, Red1, 32
Red, Red2, 17
Red, Red3, 7
Orange, Orange1, 22
Orange, Orange2, 11
Orange, Orange3, 6
Yellow, Yellow1, 14
Yellow, Yellow2, 12
;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This is the desired output:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Hello_there_0-1668031110801.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/77136i1F3A01DCF0776BDD/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Hello_there_0-1668031110801.png" alt="Hello_there_0-1668031110801.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Nov 2022 21:59:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-the-most-efficient-way-to-add-down-per-column-per-group/m-p/843481#M333468</guid>
      <dc:creator>Hello_there</dc:creator>
      <dc:date>2022-11-09T21:59:05Z</dc:date>
    </item>
    <item>
      <title>Re: What is the most efficient way to add down per column per group?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-the-most-efficient-way-to-add-down-per-column-per-group/m-p/843483#M333469</link>
      <description>&lt;P&gt;SQL is the easiest method to program&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as 
select *, sum(count1) as want
from have
group by maincat
order by 1, 2;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;A href="https://github.com/statgeek/SAS-Tutorials/blob/master/add_average_value_to_dataset.sas" target="_blank"&gt;https://github.com/statgeek/SAS-Tutorials/blob/master/add_average_value_to_dataset.sas&lt;/A&gt;&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/252358"&gt;@Hello_there&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello, I'm trying to add down the column per group and merge that total back into the original data set. What is the most efficient way to do this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;Note: The variable MAINCAT contains the groups that i need the totals for.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines dsd dlm=",";
	input maincat $ subcat $ count1;
datalines;
Red, Red1, 32
Red, Red2, 17
Red, Red3, 7
Orange, Orange1, 22
Orange, Orange2, 11
Orange, Orange3, 6
Yellow, Yellow1, 14
Yellow, Yellow2, 12
;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This is the desired output:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Hello_there_0-1668031110801.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/77136i1F3A01DCF0776BDD/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Hello_there_0-1668031110801.png" alt="Hello_there_0-1668031110801.png" /&gt;&lt;/span&gt;&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Nov 2022 22:03:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-the-most-efficient-way-to-add-down-per-column-per-group/m-p/843483#M333469</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-11-09T22:03:32Z</dc:date>
    </item>
    <item>
      <title>Re: What is the most efficient way to add down per column per group?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-the-most-efficient-way-to-add-down-per-column-per-group/m-p/843484#M333470</link>
      <description>This was helpful. Thanks!</description>
      <pubDate>Wed, 09 Nov 2022 22:05:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-the-most-efficient-way-to-add-down-per-column-per-group/m-p/843484#M333470</guid>
      <dc:creator>Hello_there</dc:creator>
      <dc:date>2022-11-09T22:05:13Z</dc:date>
    </item>
    <item>
      <title>Re: What is the most efficient way to add down per column per group?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/What-is-the-most-efficient-way-to-add-down-per-column-per-group/m-p/843485#M333471</link>
      <description>&lt;P&gt;Define the measures you use to determine "most efficient".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One way, if you don't mind the order of records changing a bit:&lt;/P&gt;
&lt;PRE&gt;
Proc sql;
   create table want as
   select maincat, subcat, count1, sum(count1) as want
   from have
   group by maincat
   order by maincat, subcat
   ;
run;&lt;/PRE&gt;
&lt;P&gt;Otherwise use proc summary to total the values and "merge" back using a Merge statement though you are going to run into some order issues requiring sorting before the Merge and the order will end up similar to the above.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Nov 2022 22:05:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/What-is-the-most-efficient-way-to-add-down-per-column-per-group/m-p/843485#M333471</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-11-09T22:05:18Z</dc:date>
    </item>
  </channel>
</rss>

