<?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: sum total each id in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/sum-total-each-id/m-p/718211#M222228</link>
    <description>&lt;P&gt;There were errors in the code you posted:&lt;/P&gt;
&lt;P&gt;1) For observation 2-5 there was an excess TAB character ('09'x) between the ID and sun1;&lt;/P&gt;
&lt;P&gt;2) The input to proc tabulate should probably be&amp;nbsp;&lt;STRONG&gt;students&lt;/STRONG&gt; and not&amp;nbsp;&lt;STRONG&gt;mydata&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;3) To shorten list of variables replace&amp;nbsp;&lt;STRONG&gt;sub1 sub2 ...&lt;/STRONG&gt; by&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;sub:&lt;/STRONG&gt; - with the colon character. You missed the colon within all methods.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Next code is working:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data students;
infile datalines;
input id sub1  sub2 sub3 sub4 sub5		;
datalines;
1 35 55 66 41 53
2 22 44 35 46 55
3 35 88 95 55 25
4 39 78 96 44 74
5 45 71 60 90 35
;
run;

proc means data=students sum maxdec=0;
class id;
var sub:;
run;



proc tabulate data=students f=6. out=work.tabout;
class id;
var sub:;
tables id, (sub:)*(N sum);
run;



proc report data=students nowd out=work.repout;
column id sub1 sub2 sub2 sub3 sub4 sub5 ;
define id / group style(column)=Header;
define sub: / n 'Count ';
define sub:/ sum 'sub Sum';
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 10 Feb 2021 12:36:45 GMT</pubDate>
    <dc:creator>Shmuel</dc:creator>
    <dc:date>2021-02-10T12:36:45Z</dc:date>
    <item>
      <title>sum total each id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-total-each-id/m-p/718201#M222224</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data students;
input id sub1  sub2 sub3 sub4 sub5		;
datalines;
1 35 55 66 41 53
2	22 44 35 46 55
3	35 88 95 55 25
4	39 78 96 44 74
5	45 71 60 90 35
;
run;

proc means data=students sum maxdec=0;
class id;
var sub;
run;



proc tabulate data=mydata f=6. out=work.tabout;
class id;
var sub;
tables id, sub*(N sum);
run;



proc report data=students nowd out=work.repout;
column id sub1 sub2 sub2 sub3 sub4 sub5 ;
define id / group style(column)=Header;
define sub / n 'Count ';
define sub/ sum 'sub Sum';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Sum the students marks with different procedures&lt;/P&gt;</description>
      <pubDate>Wed, 10 Feb 2021 12:07:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-total-each-id/m-p/718201#M222224</guid>
      <dc:creator>BrahmanandaRao</dc:creator>
      <dc:date>2021-02-10T12:07:40Z</dc:date>
    </item>
    <item>
      <title>Re: sum total each id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-total-each-id/m-p/718204#M222226</link>
      <description>&lt;P&gt;What is your question?&lt;/P&gt;</description>
      <pubDate>Wed, 10 Feb 2021 12:19:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-total-each-id/m-p/718204#M222226</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-02-10T12:19:08Z</dc:date>
    </item>
    <item>
      <title>Re: sum total each id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-total-each-id/m-p/718206#M222227</link>
      <description>&lt;P&gt;As with most problems, a long data set makes things much simpler&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data students;
input id sub1-sub5;
datalines;
1 35 55 66 41 53
2 22 44 35 46 55
3 35 88 95 55 25
4 39 78 96 44 74
5 45 71 60 90 35
;

data long(drop = sub1-sub5);
   set students;
   array s sub:;
   do over s;
      sub = s;
      output;
   end;
run;

proc means data = long sum;
   class id;
   var sub;
run;

proc tabulate data=long;
   class id;
   var sub;
   tables id, sub=''*(N sum);
run;

proc report data = long;
    columns id sub;
    define id  / group;
    define sub / analysis sum;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 10 Feb 2021 12:22:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-total-each-id/m-p/718206#M222227</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-02-10T12:22:41Z</dc:date>
    </item>
    <item>
      <title>Re: sum total each id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-total-each-id/m-p/718211#M222228</link>
      <description>&lt;P&gt;There were errors in the code you posted:&lt;/P&gt;
&lt;P&gt;1) For observation 2-5 there was an excess TAB character ('09'x) between the ID and sun1;&lt;/P&gt;
&lt;P&gt;2) The input to proc tabulate should probably be&amp;nbsp;&lt;STRONG&gt;students&lt;/STRONG&gt; and not&amp;nbsp;&lt;STRONG&gt;mydata&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;3) To shorten list of variables replace&amp;nbsp;&lt;STRONG&gt;sub1 sub2 ...&lt;/STRONG&gt; by&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;sub:&lt;/STRONG&gt; - with the colon character. You missed the colon within all methods.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Next code is working:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data students;
infile datalines;
input id sub1  sub2 sub3 sub4 sub5		;
datalines;
1 35 55 66 41 53
2 22 44 35 46 55
3 35 88 95 55 25
4 39 78 96 44 74
5 45 71 60 90 35
;
run;

proc means data=students sum maxdec=0;
class id;
var sub:;
run;



proc tabulate data=students f=6. out=work.tabout;
class id;
var sub:;
tables id, (sub:)*(N sum);
run;



proc report data=students nowd out=work.repout;
column id sub1 sub2 sub2 sub3 sub4 sub5 ;
define id / group style(column)=Header;
define sub: / n 'Count ';
define sub:/ sum 'sub Sum';
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 10 Feb 2021 12:36:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-total-each-id/m-p/718211#M222228</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2021-02-10T12:36:45Z</dc:date>
    </item>
    <item>
      <title>Re: sum total each id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-total-each-id/m-p/718259#M222247</link>
      <description>I WANT EACH STUDENT ID  SUBJECTS TOTAL (SUM) BUT ABOVE CODE WRONG</description>
      <pubDate>Wed, 10 Feb 2021 14:43:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-total-each-id/m-p/718259#M222247</guid>
      <dc:creator>BrahmanandaRao</dc:creator>
      <dc:date>2021-02-10T14:43:47Z</dc:date>
    </item>
    <item>
      <title>Re: sum total each id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-total-each-id/m-p/718272#M222253</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/265860"&gt;@BrahmanandaRao&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I WANT EACH STUDENT ID SUBJECTS TOTAL (SUM) BUT ABOVE CODE WRONG&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What is wrong with it? You must know what is wrong, why don't you tell us?&lt;/P&gt;</description>
      <pubDate>Wed, 10 Feb 2021 15:31:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-total-each-id/m-p/718272#M222253</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-02-10T15:31:11Z</dc:date>
    </item>
    <item>
      <title>Re: sum total each id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-total-each-id/m-p/718274#M222255</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/265860"&gt;@BrahmanandaRao&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I WANT EACH STUDENT ID SUBJECTS TOTAL (SUM) BUT ABOVE CODE WRONG&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you want to Sub1+Sub2+Sub3+Sub4+Sub5 for each ID then none of the procedures is ideal though you can force report to do so.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want;
   set students;
   total = sum(of sub:);
run;&lt;/PRE&gt;
&lt;P&gt;Or reshape the data as &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt; suggests.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And don't shout in all capital letters. You will get better responses if you SHOW what you expect a result to be.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Feb 2021 15:31:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-total-each-id/m-p/718274#M222255</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-02-10T15:31:55Z</dc:date>
    </item>
    <item>
      <title>Re: sum total each id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-total-each-id/m-p/718278#M222259</link>
      <description>&lt;P&gt;If I understand you correctly you want the horizontal sum of subject per row in a report&lt;/P&gt;
&lt;P&gt;then check next codes:&lt;/P&gt;
&lt;P&gt;(1) summing all SUBs in a &lt;STRONG&gt;row&lt;/STRONG&gt;:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data students;
infile datalines;
input id sub1  sub2 sub3 sub4 sub5;
total = sum(of sub:);
datalines;
1 35 55 66 41 53
2 22 44 35 46 55
3 35 88 95 55 25
4 39 78 96 44 74
5 45 71 60 90 35
;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;2) Adding the total column in proc &lt;STRONG&gt;tabulate&lt;/STRONG&gt;:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc tabulate data=students f=6. out=work.tabout;
class id;
var sub: total;
tables id, ((sub:) total)*(N sum);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;3)&amp;nbsp;Adding the total column in proc &lt;STRONG&gt;means&lt;/STRONG&gt;:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc means data=students sum maxdec=0;
class id;
var sub: total;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;4)&amp;nbsp;Adding the total column in proc &lt;STRONG&gt;report&lt;/STRONG&gt;:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc report data=students nowd out=work.repout;
column id sub1 sub2 sub2 sub3 sub4 sub5 total;
define id / group style(column)=Header;
define sub: / sum "sub Sum";
define total/ sum 'Total Sum';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I don't know if it is possible to show two different statistics of same variable(s).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the out of above code is not what you want then post the format of the wanted report&lt;/P&gt;</description>
      <pubDate>Wed, 10 Feb 2021 15:47:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-total-each-id/m-p/718278#M222259</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2021-02-10T15:47:38Z</dc:date>
    </item>
    <item>
      <title>Re: sum total each id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-total-each-id/m-p/718411#M222340</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88384"&gt;@Shmuel&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I don't know if it is possible to show two different statistics of same variable(s).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I am assuming the comment is for proc report.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc report data=sashelp.class;
   columns sex height,(min mean max);
   define sex /group;
   define height/ analysis;
run;&lt;/PRE&gt;
&lt;P&gt;is one way unless you had something more complex in mind for the multiple statistics.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Feb 2021 21:30:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-total-each-id/m-p/718411#M222340</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-02-10T21:30:44Z</dc:date>
    </item>
    <item>
      <title>Re: sum total each id</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sum-total-each-id/m-p/718479#M222366</link>
      <description>&lt;P&gt;Thanks to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;I can present here the proc report too:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc report data=students nowd out=work.repout;
column id sub1 sub2 sub2 sub3 sub4 sub5 total, (N sum);
define id / group style(column)=Header;
define sub1 / display  ;
define sub2 / display ;
define sub3 / display ;
define sub4 / display ;
define sub5 / display ;
define total/ sum 'Total Sum';
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 11 Feb 2021 05:33:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sum-total-each-id/m-p/718479#M222366</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2021-02-11T05:33:38Z</dc:date>
    </item>
  </channel>
</rss>

