<?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: Add new row with the sum of specific rows in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Add-new-row-with-the-sum-of-specific-rows/m-p/769862#M244145</link>
    <description>&lt;P&gt;double-post: I got it! I just put the Where-command into the summary-command, built a table per sum-group and combined all tables afterwards.&lt;BR /&gt;&lt;BR /&gt;Thanks!&lt;/P&gt;</description>
    <pubDate>Thu, 23 Sep 2021 10:29:43 GMT</pubDate>
    <dc:creator>Konkordanz</dc:creator>
    <dc:date>2021-09-23T10:29:43Z</dc:date>
    <item>
      <title>Add new row with the sum of specific rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-new-row-with-the-sum-of-specific-rows/m-p/769169#M244016</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have &amp;gt;5.000 rows and 130 columns.&lt;/P&gt;
&lt;P&gt;Column 1: Postal codes (inkl.duplicates)&lt;/P&gt;
&lt;P&gt;Column 2-129 with €-values (names of columns: sp1-sp129)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What I need is a new row with the result of the sum of all rows for each numeric column (sp1-sp129), if the postal code is XXXXX. How can I do this with a short sql-code? &lt;STRONG&gt;Thank you for help!&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example:&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 180pt;" border="0" width="239px" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD width="104px" height="16" style="height: 12.0pt; width: 60pt;"&gt;&lt;STRONG&gt;postal_code&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="45px" style="width: 60pt;"&gt;&lt;STRONG&gt;sp1&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="45px" style="width: 60pt;"&gt;&lt;STRONG&gt;sp2&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="45px" style="width: 60pt;"&gt;&lt;STRONG&gt;spN&lt;BR /&gt;&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD width="104px" height="16" align="right" style="height: 12.0pt;"&gt;11111&lt;/TD&gt;
&lt;TD width="45px" align="right"&gt;65&lt;/TD&gt;
&lt;TD width="45px" align="right"&gt;78&lt;/TD&gt;
&lt;TD width="45px"&gt;...&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD width="104px" height="16" align="right" style="height: 12.0pt;"&gt;11111&lt;/TD&gt;
&lt;TD width="45px" align="right"&gt;12&lt;/TD&gt;
&lt;TD width="45px" align="right"&gt;65&lt;/TD&gt;
&lt;TD width="45px"&gt;...&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD width="104px" height="16" align="right" style="height: 12.0pt;"&gt;22222&lt;/TD&gt;
&lt;TD width="45px" align="right"&gt;87&lt;/TD&gt;
&lt;TD width="45px" align="right"&gt;21&lt;/TD&gt;
&lt;TD width="45px"&gt;...&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD width="104px" height="16" align="right" style="height: 12.0pt;"&gt;33333&lt;/TD&gt;
&lt;TD width="45px" align="right"&gt;42&lt;/TD&gt;
&lt;TD width="45px" align="right"&gt;45&lt;/TD&gt;
&lt;TD width="45px"&gt;...&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD width="104px" height="16" align="right" style="height: 12.0pt;"&gt;22222&lt;/TD&gt;
&lt;TD width="45px" align="right"&gt;65&lt;/TD&gt;
&lt;TD width="45px" align="right"&gt;87&lt;/TD&gt;
&lt;TD width="45px"&gt;...&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD width="104px" height="16" align="right" style="height: 12.0pt;"&gt;11111&lt;/TD&gt;
&lt;TD width="45px" align="right"&gt;24&lt;/TD&gt;
&lt;TD width="45px" align="right"&gt;86&lt;/TD&gt;
&lt;TD width="45px"&gt;...&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD width="104px" height="16" style="height: 12.0pt;"&gt;1111_sum&lt;/TD&gt;
&lt;TD width="45px" align="right"&gt;101&lt;/TD&gt;
&lt;TD width="45px" align="right"&gt;229&lt;/TD&gt;
&lt;TD width="45px"&gt;...&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Wed, 22 Sep 2021 13:52:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-new-row-with-the-sum-of-specific-rows/m-p/769169#M244016</guid>
      <dc:creator>Konkordanz</dc:creator>
      <dc:date>2021-09-22T13:52:49Z</dc:date>
    </item>
    <item>
      <title>Re: Add new row with the sum of specific rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-new-row-with-the-sum-of-specific-rows/m-p/769176#M244021</link>
      <description>&lt;P&gt;I wouldn't even attempt this in PROC SQL&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=have nway;
    class postal_code;
    var sp1-sp129;
    output out=_sums_ sum=;
run;

proc sort data=have;
    by postal_code;
run;

data want;
    length postal_code $ 10;
    set have _sums_;
    by postal_code;
    if _type_=1 then postal_code=cats(postal_code,'_sum');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Sep 2021 14:33:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-new-row-with-the-sum-of-specific-rows/m-p/769176#M244021</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-09-22T14:33:24Z</dc:date>
    </item>
    <item>
      <title>Re: Add new row with the sum of specific rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-new-row-with-the-sum-of-specific-rows/m-p/769184#M244026</link>
      <description>&lt;P&gt;How do you include duplicates with the different values but then sum them up if the postal code is XXX? Those are contradictory requirements.&lt;/P&gt;
&lt;P&gt;Do you mean you only want postal codes with the same characters added up, ie with the pattern of letters and just the total at the bottom? Do you expect to see a line of 22222_sum as well?&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/388612"&gt;@Konkordanz&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have &amp;gt;5.000 rows and 130 columns.&lt;/P&gt;
&lt;P&gt;Column 1: Postal codes (inkl.duplicates)&lt;/P&gt;
&lt;P&gt;Column 2-129 with €-values (names of columns: sp1-sp129)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What I need is a&lt;FONT color="#FF0000"&gt; new row with the result of the sum of all rows for each numeric column (sp1-sp129), if the postal code is XXXXX&lt;/FONT&gt;. How can I do this with a short sql-code? &lt;STRONG&gt;Thank you for help!&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example:&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 180pt;" border="0" width="239px" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD width="104px" height="16" style="height: 12.0pt; width: 60pt;"&gt;&lt;STRONG&gt;postal_code&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="45px" style="width: 60pt;"&gt;&lt;STRONG&gt;sp1&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="45px" style="width: 60pt;"&gt;&lt;STRONG&gt;sp2&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="45px" style="width: 60pt;"&gt;&lt;STRONG&gt;spN&lt;BR /&gt;&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD width="104px" height="16" align="right" style="height: 12.0pt;"&gt;&lt;FONT color="#FF0000"&gt;11111&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="45px" align="right"&gt;&lt;FONT color="#FF0000"&gt;65&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="45px" align="right"&gt;&lt;FONT color="#FF0000"&gt;78&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="45px"&gt;&lt;FONT color="#FF0000"&gt;...&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD width="104px" height="16" align="right" style="height: 12.0pt;"&gt;&lt;FONT color="#FF0000"&gt;11111&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="45px" align="right"&gt;&lt;FONT color="#FF0000"&gt;12&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="45px" align="right"&gt;&lt;FONT color="#FF0000"&gt;65&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="45px"&gt;&lt;FONT color="#FF0000"&gt;...&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD width="104px" height="16" align="right" style="height: 12.0pt;"&gt;22222&lt;/TD&gt;
&lt;TD width="45px" align="right"&gt;87&lt;/TD&gt;
&lt;TD width="45px" align="right"&gt;21&lt;/TD&gt;
&lt;TD width="45px"&gt;...&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD width="104px" height="16" align="right" style="height: 12.0pt;"&gt;33333&lt;/TD&gt;
&lt;TD width="45px" align="right"&gt;42&lt;/TD&gt;
&lt;TD width="45px" align="right"&gt;45&lt;/TD&gt;
&lt;TD width="45px"&gt;...&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD width="104px" height="16" align="right" style="height: 12.0pt;"&gt;22222&lt;/TD&gt;
&lt;TD width="45px" align="right"&gt;65&lt;/TD&gt;
&lt;TD width="45px" align="right"&gt;87&lt;/TD&gt;
&lt;TD width="45px"&gt;...&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD width="104px" height="16" align="right" style="height: 12.0pt;"&gt;&lt;FONT color="#FF0000"&gt;11111&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="45px" align="right"&gt;&lt;FONT color="#FF0000"&gt;24&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="45px" align="right"&gt;&lt;FONT color="#FF0000"&gt;86&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="45px"&gt;&lt;FONT color="#FF0000"&gt;...&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.0pt;"&gt;
&lt;TD width="104px" height="16" style="height: 12.0pt;"&gt;1111_sum&lt;/TD&gt;
&lt;TD width="45px" align="right"&gt;101&lt;/TD&gt;
&lt;TD width="45px" align="right"&gt;229&lt;/TD&gt;
&lt;TD width="45px"&gt;...&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Sep 2021 14:44:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-new-row-with-the-sum-of-specific-rows/m-p/769184#M244026</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-09-22T14:44:32Z</dc:date>
    </item>
    <item>
      <title>Re: Add new row with the sum of specific rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-new-row-with-the-sum-of-specific-rows/m-p/769811#M244124</link>
      <description>Thank for response and sry for inaccurate description! &lt;BR /&gt;Well, I actually dont want to sum all postal-codes. I mean...it would be okay, afterwards I would just filter away the lines i doesnt need. But actually I want to sum certain codes; in my example the 11111. So I need a way to summarize the certain data with a filter and add the result as a new row into my dataset. Do you have a short solution? thanks!</description>
      <pubDate>Thu, 23 Sep 2021 08:22:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-new-row-with-the-sum-of-specific-rows/m-p/769811#M244124</guid>
      <dc:creator>Konkordanz</dc:creator>
      <dc:date>2021-09-23T08:22:43Z</dc:date>
    </item>
    <item>
      <title>Re: Add new row with the sum of specific rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-new-row-with-the-sum-of-specific-rows/m-p/769812#M244125</link>
      <description>Thank for response, is working...but: actually I dont want to sum all postal-codes But only certain codes; in my example the 11111. So I need a way to summarize the certain data with a filter and add the result as a new row into my dataset. Do you have a short solution? thanks!</description>
      <pubDate>Thu, 23 Sep 2021 08:24:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-new-row-with-the-sum-of-specific-rows/m-p/769812#M244125</guid>
      <dc:creator>Konkordanz</dc:creator>
      <dc:date>2021-09-23T08:24:57Z</dc:date>
    </item>
    <item>
      <title>Re: Add new row with the sum of specific rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-new-row-with-the-sum-of-specific-rows/m-p/769855#M244140</link>
      <description>&lt;P&gt;It's often useful to show the desired result based on the sample data (ideally provided via a SAS data step). Below 3 want options for what you might ask for. Check if any of the options fits your requirement or else let us know what comes closest and what's still missing.&lt;/P&gt;
&lt;P&gt;As for a total line: That's then more about creating a report than a new table. So if you need a report then please tell us - and SHOW us how this report would need to look like.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input postal_code $ sp1 sp2;
datalines;
11111 65 78
11111 12 65
22222 87 21
33333 42 45
22222 65 87
11111 24 86
;

data want_1;
  set have;
  spN=sum(of sp:);
run;
data want_2;
  set have;
  if postal_code='11111' then
    spN=sum(of sp:);
run;
data want_3;
  set have;
  if postal_code='11111';
  spN=sum(of sp:);
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 Sep 2021 09:49:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-new-row-with-the-sum-of-specific-rows/m-p/769855#M244140</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-09-23T09:49:38Z</dc:date>
    </item>
    <item>
      <title>Re: Add new row with the sum of specific rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-new-row-with-the-sum-of-specific-rows/m-p/769862#M244145</link>
      <description>&lt;P&gt;double-post: I got it! I just put the Where-command into the summary-command, built a table per sum-group and combined all tables afterwards.&lt;BR /&gt;&lt;BR /&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 23 Sep 2021 10:29:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-new-row-with-the-sum-of-specific-rows/m-p/769862#M244145</guid>
      <dc:creator>Konkordanz</dc:creator>
      <dc:date>2021-09-23T10:29:43Z</dc:date>
    </item>
  </channel>
</rss>

