<?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 Add total to first row in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Add-total-to-first-row/m-p/518699#M140408</link>
    <description>Hai all ,&lt;BR /&gt;I have a data like this.&lt;BR /&gt;&lt;BR /&gt;A. B&lt;BR /&gt;World 25&lt;BR /&gt;India 30&lt;BR /&gt;USA 40&lt;BR /&gt;Pak 70&lt;BR /&gt;&lt;BR /&gt;I want sum of total into world b column&lt;BR /&gt;Like&lt;BR /&gt;World 165&lt;BR /&gt;India 30&lt;BR /&gt;USA 40&lt;BR /&gt;Pak 70&lt;BR /&gt;Thanks in adv</description>
    <pubDate>Wed, 05 Dec 2018 08:27:42 GMT</pubDate>
    <dc:creator>bollurajkumar</dc:creator>
    <dc:date>2018-12-05T08:27:42Z</dc:date>
    <item>
      <title>Add total to first row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-total-to-first-row/m-p/518699#M140408</link>
      <description>Hai all ,&lt;BR /&gt;I have a data like this.&lt;BR /&gt;&lt;BR /&gt;A. B&lt;BR /&gt;World 25&lt;BR /&gt;India 30&lt;BR /&gt;USA 40&lt;BR /&gt;Pak 70&lt;BR /&gt;&lt;BR /&gt;I want sum of total into world b column&lt;BR /&gt;Like&lt;BR /&gt;World 165&lt;BR /&gt;India 30&lt;BR /&gt;USA 40&lt;BR /&gt;Pak 70&lt;BR /&gt;Thanks in adv</description>
      <pubDate>Wed, 05 Dec 2018 08:27:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-total-to-first-row/m-p/518699#M140408</guid>
      <dc:creator>bollurajkumar</dc:creator>
      <dc:date>2018-12-05T08:27:42Z</dc:date>
    </item>
    <item>
      <title>Re: Add total to first row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-total-to-first-row/m-p/518701#M140410</link>
      <description>&lt;P&gt;In a data set or report?&lt;/P&gt;</description>
      <pubDate>Wed, 05 Dec 2018 08:30:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-total-to-first-row/m-p/518701#M140410</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2018-12-05T08:30:26Z</dc:date>
    </item>
    <item>
      <title>Re: Add total to first row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-total-to-first-row/m-p/518708#M140415</link>
      <description>&lt;P&gt;In either case, you can do something like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input A $ B;
datalines;
World 25
India 30
USA 40
Pak 70
;

proc sql;
   create table want as
   select 'World' as A, sum(B) as B from have
   union
   select * from have where A ne 'World'
   order by B descending;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 05 Dec 2018 09:09:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-total-to-first-row/m-p/518708#M140415</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2018-12-05T09:09:48Z</dc:date>
    </item>
    <item>
      <title>Re: Add total to first row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-total-to-first-row/m-p/518710#M140417</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input  A $ B;
datalines;
World 25
India 30
USA 40
Pak 70
;
run;

proc report data=have;
column a b;
define a/order descending;
define a/order;
rbreak before /summarize;
run;

DATA WANT;
SET HAVE;
RETAIN S 0;
S=S+B;
if a='World' then call sortn(s,b);
else call sortn(b,s);
drop s;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Dec 2018 09:16:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-total-to-first-row/m-p/518710#M140417</guid>
      <dc:creator>singhsahab</dc:creator>
      <dc:date>2018-12-05T09:16:33Z</dc:date>
    </item>
    <item>
      <title>Re: Add total to first row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-total-to-first-row/m-p/518712#M140418</link>
      <description>&lt;P&gt;I had a slightly different take on the SQL:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select
  a,
  case
    when a = 'World' then (select sum(b) from have)
    else b
  end as b
from have;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 05 Dec 2018 09:28:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-total-to-first-row/m-p/518712#M140418</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-12-05T09:28:08Z</dc:date>
    </item>
    <item>
      <title>Re: Add total to first row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-total-to-first-row/m-p/518718#M140419</link>
      <description>&lt;P&gt;By 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  A $ B;
datalines;
World 25
India 30
USA 40
Pak 70
;
run;

data want;
set have;
if a='World' then sort=1;
else sort=0;
call sortn(sort,b);
run;

proc sort data=want;
by sort;
run;

DATA WANT2;
SET want;
by sort;
S+B;
if a='World' then b=s;
else b=b;
drop s;
RUN;&lt;BR /&gt;&lt;BR /&gt;proc sort data=want2;&lt;BR /&gt;by sort;&lt;BR /&gt;run;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 05 Dec 2018 10:07:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-total-to-first-row/m-p/518718#M140419</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2018-12-05T10:07:15Z</dc:date>
    </item>
    <item>
      <title>Re: Add total to first row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-total-to-first-row/m-p/518726#M140422</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input A $ B;
datalines;
World 25
India 30
USA 40
Pak 70
;


data _null_ ;
if _n_=1 then do;
   declare hash H (ordered:'a') ;
   h.definekey  ("_n_") ;
   h.definedata ("a", "b") ;
   h.definedone () ;
   end;
set have end=lr;
rc=h.add();
k+b;
if lr;
_n_=1;
h.find();
b=k;
h.replace();
h.output(dataset:'want');
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 05 Dec 2018 10:48:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-total-to-first-row/m-p/518726#M140422</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-12-05T10:48:38Z</dc:date>
    </item>
    <item>
      <title>Re: Add total to first row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-total-to-first-row/m-p/518732#M140426</link>
      <description>&lt;P&gt;More fun&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input A $ B;
datalines;
World 25
India 30
USA 40
Pak 70
;
data _null_ ;
if _n_=1 then do;
   declare hash H (ordered:'a') ;
   h.definekey  ("_n_") ;
   h.definedata ("a", "b") ;
   h.definedone () ;
   end;
do _n_=nobs to 1 by -1;
set have nobs=nobs point=_n_;
k+b;
if _n_=1 then b=k;
rc=h.add();
end;
h.output(dataset:'want');
stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 05 Dec 2018 11:02:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-total-to-first-row/m-p/518732#M140426</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-12-05T11:02:34Z</dc:date>
    </item>
    <item>
      <title>Re: Add total to first row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-total-to-first-row/m-p/518914#M140470</link>
      <description>&lt;P&gt;And more fun:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input A $ B;
datalines;
World 25
India 30
USA 40
Pak 70
;


proc sql;
create table want as
select a, ifn(monotonic()=1,sum(b),b) as b
from have
order by monotonic();
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 05 Dec 2018 19:36:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-total-to-first-row/m-p/518914#M140470</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-12-05T19:36:28Z</dc:date>
    </item>
  </channel>
</rss>

