<?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: insert a row at the end of specific rows with Totals in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/insert-a-row-at-the-end-of-specific-rows-with-Totals/m-p/518005#M140144</link>
    <description>&lt;P&gt;Thanks a lot, this works.&lt;/P&gt;</description>
    <pubDate>Mon, 03 Dec 2018 10:35:01 GMT</pubDate>
    <dc:creator>chithra</dc:creator>
    <dc:date>2018-12-03T10:35:01Z</dc:date>
    <item>
      <title>insert a row at the end of specific rows with Totals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/insert-a-row-at-the-end-of-specific-rows-with-Totals/m-p/517992#M140138</link>
      <description>&lt;P&gt;Dear All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset like below;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; have;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; a1 &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;$12.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; a b;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;cards&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;IME_PREM_ADJ 11 100&lt;/P&gt;&lt;P&gt;IME_PREM_ADJ 12 102&lt;/P&gt;&lt;P&gt;IME_PREM_NON 11 101&lt;/P&gt;&lt;P&gt;IME_PREM_ADJ 13 101&lt;/P&gt;&lt;P&gt;IME_PREM_RES 11 105&lt;/P&gt;&lt;P&gt;IME_PREM_RES 3 102&lt;/P&gt;&lt;P&gt;IME_PREM_NON 2 200&lt;/P&gt;&lt;P&gt;IME_ANNUITIE 3 205&lt;/P&gt;&lt;P&gt;IME_ANNUITIE 4 501&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to sum the b row using a1 by group, and insert a row of TOTAL in the a column for each a1 by group with the sum.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The output will be :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;IME_ANNUITIE&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;205&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;IME_ANNUITIE&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;501&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;IME_ANNUITIE&lt;/TD&gt;&lt;TD&gt;TOTAL&lt;/TD&gt;&lt;TD&gt;706&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;IME_PREM_ADJ&lt;/TD&gt;&lt;TD&gt;11&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;IME_PREM_ADJ&lt;/TD&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;TD&gt;102&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;IME_PREM_ADJ&lt;/TD&gt;&lt;TD&gt;13&lt;/TD&gt;&lt;TD&gt;101&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;IME_PREM_ADJ&lt;/TD&gt;&lt;TD&gt;TOTAL&lt;/TD&gt;&lt;TD&gt;303&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;IME_PREM_NON&lt;/TD&gt;&lt;TD&gt;11&lt;/TD&gt;&lt;TD&gt;101&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;IME_PREM_NON&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;200&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;IME_PREM_NON&lt;/TD&gt;&lt;TD&gt;TOTAL&lt;/TD&gt;&lt;TD&gt;301&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;IME_PREM_RES&lt;/TD&gt;&lt;TD&gt;11&lt;/TD&gt;&lt;TD&gt;105&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;IME_PREM_RES&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;102&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;IME_PREM_RES&lt;/TD&gt;&lt;TD&gt;TOTAL&lt;/TD&gt;&lt;TD&gt;207&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance,&lt;/P&gt;&lt;P&gt;Chithra&lt;/P&gt;</description>
      <pubDate>Mon, 03 Dec 2018 09:21:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/insert-a-row-at-the-end-of-specific-rows-with-Totals/m-p/517992#M140138</guid>
      <dc:creator>chithra</dc:creator>
      <dc:date>2018-12-03T09:21:47Z</dc:date>
    </item>
    <item>
      <title>Re: insert a row at the end of specific rows with Totals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/insert-a-row-at-the-end-of-specific-rows-with-Totals/m-p/517995#M140139</link>
      <description>&lt;P&gt;Please use the search functionality before posting a question, I can think of at least two questions from last week which were more or less the same as this.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/forums/searchpage/tab/message?advanced=false&amp;amp;allow_punctuation=false&amp;amp;q=total+row" target="_blank"&gt;https://communities.sas.com/t5/forums/searchpage/tab/message?advanced=false&amp;amp;allow_punctuation=false&amp;amp;q=total+row&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Dec 2018 09:34:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/insert-a-row-at-the-end-of-specific-rows-with-Totals/m-p/517995#M140139</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-12-03T09:34:37Z</dc:date>
    </item>
    <item>
      <title>Re: insert a row at the end of specific rows with Totals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/insert-a-row-at-the-end-of-specific-rows-with-Totals/m-p/517998#M140141</link>
      <description>&lt;P&gt;&amp;nbsp;yes, but which doesn't fit my answer.&lt;/P&gt;&lt;P&gt;I need the TOTAL's in a different way.&lt;/P&gt;</description>
      <pubDate>Mon, 03 Dec 2018 10:01:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/insert-a-row-at-the-end-of-specific-rows-with-Totals/m-p/517998#M140141</guid>
      <dc:creator>chithra</dc:creator>
      <dc:date>2018-12-03T10:01:39Z</dc:date>
    </item>
    <item>
      <title>Re: insert a row at the end of specific rows with Totals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/insert-a-row-at-the-end-of-specific-rows-with-Totals/m-p/518000#M140142</link>
      <description>&lt;PRE&gt;data have;
input a1 $12. a b;
cards;
IME_PREM_ADJ 11 100
IME_PREM_ADJ 12 102
IME_PREM_NON 11 101
IME_PREM_ADJ 13 101
IME_PREM_RES 11 105
IME_PREM_RES 3 102
IME_PREM_NON 2 200
IME_ANNUITIE 3 205
IME_ANNUITIE 4 501
;
run;

data want;
  set have;
  by a1 notsorted;
  retain cnt;
  cnt=ifn(first.a1,b,sum(cnt,b));
  if not last.a1 then output;
  else do;
    output;
    a1="TOTAL";
    b=cnt;
    output;
  end;
run;&lt;/PRE&gt;</description>
      <pubDate>Mon, 03 Dec 2018 10:08:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/insert-a-row-at-the-end-of-specific-rows-with-Totals/m-p/518000#M140142</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-12-03T10:08:53Z</dc:date>
    </item>
    <item>
      <title>Re: insert a row at the end of specific rows with Totals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/insert-a-row-at-the-end-of-specific-rows-with-Totals/m-p/518004#M140143</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/54638"&gt;@chithra&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
by a1;
run;

proc format;
value totalf
.='TOTAL';
run;

data want(drop=tb);
do until(last.a1);
  set have;
  by a1;
  tb=sum(tb,b);
  output;
end;
a=.;
b=tb;
output;
format a totalf.;
run;

proc print data=want noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 03 Dec 2018 10:33:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/insert-a-row-at-the-end-of-specific-rows-with-Totals/m-p/518004#M140143</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2018-12-03T10:33:25Z</dc:date>
    </item>
    <item>
      <title>Re: insert a row at the end of specific rows with Totals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/insert-a-row-at-the-end-of-specific-rows-with-Totals/m-p/518005#M140144</link>
      <description>&lt;P&gt;Thanks a lot, this works.&lt;/P&gt;</description>
      <pubDate>Mon, 03 Dec 2018 10:35:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/insert-a-row-at-the-end-of-specific-rows-with-Totals/m-p/518005#M140144</guid>
      <dc:creator>chithra</dc:creator>
      <dc:date>2018-12-03T10:35:01Z</dc:date>
    </item>
  </channel>
</rss>

