<?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 a column for the row total using proc report in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/add-a-column-for-the-row-total-using-proc-report/m-p/834466#M82065</link>
    <description>&lt;P&gt;Thanks Miller.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It works now.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You are awesome!&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":smiling_face_with_smiling_eyes:"&gt;😊&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 21 Sep 2022 13:10:51 GMT</pubDate>
    <dc:creator>BeatriceWang</dc:creator>
    <dc:date>2022-09-21T13:10:51Z</dc:date>
    <item>
      <title>add a column for the row total using proc report</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/add-a-column-for-the-row-total-using-proc-report/m-p/834382#M82056</link>
      <description>&lt;P&gt;Dear Fellow SAS Procedure Users,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have below proc report code I would like to produce the total for each row and append it to the "All Combined" column. For some reason I got blanks for the total. I would like you to advise where my code is wrong and how to fix it. Apologize if this is obvious.&lt;/P&gt;
&lt;P&gt;Thanks in advance,&lt;/P&gt;
&lt;P&gt;Beatrice&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="BeatriceWang_0-1663706245272.png" style="width: 613px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/75416i266FD75F3E3B644B/image-dimensions/613x265?v=v2" width="613" height="265" role="button" title="BeatriceWang_0-1663706245272.png" alt="BeatriceWang_0-1663706245272.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Sep 2022 20:39:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/add-a-column-for-the-row-total-using-proc-report/m-p/834382#M82056</guid>
      <dc:creator>BeatriceWang</dc:creator>
      <dc:date>2022-09-20T20:39:12Z</dc:date>
    </item>
    <item>
      <title>Re: add a column for the row total using proc report</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/add-a-column-for-the-row-total-using-proc-report/m-p/834386#M82057</link>
      <description>&lt;P&gt;No data to test this on, so this is UNTESTED CODE&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;From now on, please provide code as text rather than screen capture, and by pasting it into the box that appears when you click on the "little running man" icon, like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc report data=ds1;
    column idx label (var1,stat) stat=sumstat;
/* Your DEFINE statements go here, plus another DEFINE statement */
/* Do not include DEFINE statement for N */
    define sumstat/sum f=comma18.0 "All Combined";
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 20 Sep 2022 21:24:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/add-a-column-for-the-row-total-using-proc-report/m-p/834386#M82057</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-09-20T21:24:50Z</dc:date>
    </item>
    <item>
      <title>Re: add a column for the row total using proc report</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/add-a-column-for-the-row-total-using-proc-report/m-p/834399#M82058</link>
      <description>&lt;P&gt;Thank you Miller for your suggestion.&lt;/P&gt;
&lt;P&gt;I tried but I got the following error:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="BeatriceWang_0-1663712305151.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/75417i9A6BAB3472B72A2C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="BeatriceWang_0-1663712305151.png" alt="BeatriceWang_0-1663712305151.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please note stat itself is a variable in my input dataset and it is the sum I got from proc means.&lt;/P&gt;
&lt;P&gt;Any further suggestion?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Sep 2022 22:21:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/add-a-column-for-the-row-total-using-proc-report/m-p/834399#M82058</guid>
      <dc:creator>BeatriceWang</dc:creator>
      <dc:date>2022-09-20T22:21:25Z</dc:date>
    </item>
    <item>
      <title>Re: add a column for the row total using proc report</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/add-a-column-for-the-row-total-using-proc-report/m-p/834401#M82059</link>
      <description>Output from proc means should be numeric. Show your work please. As previously mentioned, not as images.</description>
      <pubDate>Tue, 20 Sep 2022 22:24:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/add-a-column-for-the-row-total-using-proc-report/m-p/834401#M82059</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-09-20T22:24:23Z</dc:date>
    </item>
    <item>
      <title>Re: add a column for the row total using proc report</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/add-a-column-for-the-row-total-using-proc-report/m-p/834411#M82060</link>
      <description>&lt;P&gt;Thank you Reeza for your reply.&lt;/P&gt;
&lt;P&gt;Here is my original code in text format. Please kindly further suggest.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ods results=off;&lt;BR /&gt;filename fout '/C/test.xls';&lt;BR /&gt;ods excel file=fout options(embedded_titles='yes') style=Excel;&lt;BR /&gt;ods excel options(sheet_name='Table9' absolute_column_width='21' flow='tables' frozen_headers='3');&lt;BR /&gt;ods listing close;&lt;BR /&gt;proc report data=ds1 split='~';&lt;BR /&gt;column idx label (var1, stat) n;&lt;BR /&gt;define idx / noprint group;&lt;BR /&gt;define label / '' group left;&lt;BR /&gt;define var1 / '' across nozero order=internal format=anagrpnfmt.;&lt;BR /&gt;define stat / '' center;&lt;BR /&gt;define n/computed f=comma18.0 "ALL Combined";&lt;BR /&gt;compute n;&lt;BR /&gt;n=sum(stat);&lt;BR /&gt;endcomp;&lt;BR /&gt;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;ods excel close;&lt;BR /&gt;filename fout clear;&lt;BR /&gt;title;&lt;BR /&gt;ods results;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Sep 2022 23:54:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/add-a-column-for-the-row-total-using-proc-report/m-p/834411#M82060</guid>
      <dc:creator>BeatriceWang</dc:creator>
      <dc:date>2022-09-20T23:54:55Z</dc:date>
    </item>
    <item>
      <title>Re: add a column for the row total using proc report</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/add-a-column-for-the-row-total-using-proc-report/m-p/834426#M82061</link>
      <description>&lt;P&gt;Agree with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;.&lt;/P&gt;&lt;P&gt;I supply some additional information about your code.&lt;/P&gt;&lt;P&gt;According to your think,&amp;nbsp;you don't need to add a new computed column .&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc report data=ds1 split='~';
	column idx label (var1, stat) stat=n;
	define idx / noprint group;
	define label / '' group left;
	define var1 / '' across nozero order=internal format=anagrpnfmt.;
	define stat / '' center;
	define n / '' sum f=comma18.0 "ALL Combined";
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;P.S.&amp;nbsp;The error you got is that you can't use "sum()", you should key "n=stat.sum".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Fred&lt;/P&gt;</description>
      <pubDate>Wed, 21 Sep 2022 07:49:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/add-a-column-for-the-row-total-using-proc-report/m-p/834426#M82061</guid>
      <dc:creator>FM_MF</dc:creator>
      <dc:date>2022-09-21T07:49:12Z</dc:date>
    </item>
    <item>
      <title>Re: add a column for the row total using proc report</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/add-a-column-for-the-row-total-using-proc-report/m-p/834439#M82062</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/387104"&gt;@BeatriceWang&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you Miller for your suggestion.&lt;/P&gt;
&lt;P&gt;I tried but I got the following error:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="BeatriceWang_0-1663712305151.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/75417i9A6BAB3472B72A2C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="BeatriceWang_0-1663712305151.png" alt="BeatriceWang_0-1663712305151.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please note stat itself is a variable in my input dataset and it is the sum I got from proc means.&lt;/P&gt;
&lt;P&gt;Any further suggestion?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;STAT is not numeric. You cannot create totals from variables that are not numeric. Your claim that is it numeric is not correct. Show us the &lt;FONT color="#FF0000"&gt;ENTIRE&lt;/FONT&gt; LOG from before PROC REPORT of the part of your code that creates the data set DS1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please STOP showing us screen captures of text. Text, whether code or log, MUST be presented as text, using the "little running man" icon or the &amp;lt;/&amp;gt; icon (to the left of the "little running man"), respectively.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Sep 2022 11:37:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/add-a-column-for-the-row-total-using-proc-report/m-p/834439#M82062</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-09-21T11:37:36Z</dc:date>
    </item>
    <item>
      <title>Re: add a column for the row total using proc report</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/add-a-column-for-the-row-total-using-proc-report/m-p/834455#M82063</link>
      <description>&lt;PRE&gt;Hi Miller,&lt;BR /&gt;Below is my sas code with some changes from the suggestions. The total is still blank. &lt;BR /&gt;Yes. My code defined stat to character type. &lt;BR /&gt;But I am not sure how to fix it. Can you please suggest a solution?&lt;BR /&gt;&lt;BR /&gt;proc means data=ds0 sum stackodsoutput;
     class var1;
var tot_phys_ov_cnt tot_ov_pts tot_hv_pts tot_all_phys_cnt tot_all_pts_cnt; 
     ods output summary=ds1(drop=_:);
run;

data colfmt;
    set ds1;
	by var1 notsorted;

	keep fmtname start label;

	fmtname = 'anagrpnfmt';
	if first.var1 then do;
        start = var1;
		label = cats(put(var1, anagrpnfmt.),'~(N=', put(nobs, comma5.0), ')');
		output;
	end;

run;

proc format cntlin=colfmt;
run;

data ds1;
    set ds1;
	by var1 notsorted;

	label = compress(label, '|');

	if first.var1 then idx = 0;
	idx + 1;
    
	length stat $32;
	if not missing(sum) 
    then stat = strip(put(sum, 12.0)); 

run;

ods results=off;
filename fout '/c/test.xls';
ods excel file=fout options(embedded_titles='yes') style=Excel;
ods excel options(sheet_name='Table9' absolute_column_width='21' flow='tables' frozen_headers='3');
title j=left h=13pt 'test';
ods listing close;
proc report data=ds1 split='~';
    column idx label (var1, stat) n;
	define idx / noprint group;
	define label / '' group left;
	define var1 / '' across nozero order=internal format=anagrpnfmt.;
	define stat / '' center;
define n/computed f=comma18.0 "ALL Combined";
	compute n;
	n=sum(stat);
	endcomp;
run;

ods excel close;
filename fout clear;
title;
ods results;
&lt;/PRE&gt;</description>
      <pubDate>Wed, 21 Sep 2022 12:12:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/add-a-column-for-the-row-total-using-proc-report/m-p/834455#M82063</guid>
      <dc:creator>BeatriceWang</dc:creator>
      <dc:date>2022-09-21T12:12:30Z</dc:date>
    </item>
    <item>
      <title>Re: add a column for the row total using proc report</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/add-a-column-for-the-row-total-using-proc-report/m-p/834457#M82064</link>
      <description>&lt;P&gt;Here:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ds1;
    set ds1;
	by var1 notsorted;
	label = compress(label, '|');
	if first.var1 then idx = 0;
	idx + 1;  
	length stat $32;
	if not missing(sum) 
    then stat = strip(put(sum, 12.0)); 

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You have defined STAT as $32 which is character. Than later you try to assign it a character value from a numeric variable named SUM. Just use the numeric variable named SUM.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Sep 2022 12:45:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/add-a-column-for-the-row-total-using-proc-report/m-p/834457#M82064</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-09-21T12:45:47Z</dc:date>
    </item>
    <item>
      <title>Re: add a column for the row total using proc report</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/add-a-column-for-the-row-total-using-proc-report/m-p/834466#M82065</link>
      <description>&lt;P&gt;Thanks Miller.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It works now.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You are awesome!&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":smiling_face_with_smiling_eyes:"&gt;😊&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Sep 2022 13:10:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/add-a-column-for-the-row-total-using-proc-report/m-p/834466#M82065</guid>
      <dc:creator>BeatriceWang</dc:creator>
      <dc:date>2022-09-21T13:10:51Z</dc:date>
    </item>
  </channel>
</rss>

