<?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: Calculate grand total in subtotal row in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Calculate-grand-total-in-subtotal-row/m-p/605755#M17282</link>
    <description>&lt;P&gt;Hi:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; When I run in 9.4M6, I still see a NOTE with the SAME message. You got rid of the WARNINGS by fixing the COLUMN statement. Here's my log:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="still_gen_note.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/34109iB80532C0F74EBE95/image-size/large?v=v2&amp;amp;px=999" role="button" title="still_gen_note.png" alt="still_gen_note.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Do you see that NOTE? This is still something that you should consider fixing. When you have NAME in the report definition, you are NOT really "grouping" or collapsing rows. You are ORDERing the rows based on the value of the ORDER variable. And, yes, that treats each value of SEX as an ORDERed set --- for the purpose of BREAK processing. But in your usage scenario, the correct usage is ORDER.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cynthia&lt;/P&gt;</description>
    <pubDate>Wed, 20 Nov 2019 14:53:21 GMT</pubDate>
    <dc:creator>Cynthia_sas</dc:creator>
    <dc:date>2019-11-20T14:53:21Z</dc:date>
    <item>
      <title>Calculate grand total in subtotal row</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Calculate-grand-total-in-subtotal-row/m-p/605602#M17224</link>
      <description>&lt;P&gt;Hi!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to show the grand total value in a subtotal row. Take for instance SASHELP.CLASS dataset. The total sum of weights of all the students is 1900.5. The sum of weights for male students is 1089.5, and for females is 811&lt;/P&gt;&lt;P&gt;I want to create a column that, for each student, shows the weight. But, for the Sex subtotals, shows 1900.5 both for M and F (instead of 1089.5 and 811)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I found a way of achieving it, but is a little awkward. I create a dummy column as weight divided by PCTSUM to get the total. Then I create a new column that shows either the value of weight or the dummy column.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am sure there is a more straightforward way of achieving it. Any ideas? I tried using SUM instead of PCTSUM, but it doesn't calculate the grandtotal. Is there something like a TOTSUM function?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the code, the column that achieves the desired outcome is&amp;nbsp;weightCustomSubtotal&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC REPORT DATA=SASHELP.CLASS; 
	COLS SEX NAME AGE WEIGHT weight=dummy_pctsum totweight weightCustomSubtotal;
	DEFINE SEX / GROUP;
	DEFINE weightCustomSubotal / COMPUTED;

	define dummy_pctsum / analysis PCTSUM 'dummy pctsum'; 
	define dummy_totweight / COMPUTED;

	compute totweight;
		totweight = weight.sum / dummy_pctsum; 
		endcomp;
	BREAK AFTER SEX / SUMMARIZE;

	COMPUTE weightCustomSubtotal;
		IF _BREAK_ = "" THEN
			weightCustomSubtotal = weight.sum;
		ELSE 
			weightCustomSubtotal = totweight;
		ENDCOMP;
	RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks a lot!!&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, 20 Nov 2019 02:17:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Calculate-grand-total-in-subtotal-row/m-p/605602#M17224</guid>
      <dc:creator>HGimenez</dc:creator>
      <dc:date>2019-11-20T02:17:38Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate grand total in subtotal row</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Calculate-grand-total-in-subtotal-row/m-p/605622#M17227</link>
      <description>&lt;P&gt;Hi:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; It's not clear what you want to do. Your code generates these warnings that point to some of the issues.&lt;/P&gt;
&lt;DIV id="sasLogWarning1_1574224281024" class="sasWarning"&gt;&lt;FONT face="courier new,courier" color="#339966"&gt;&lt;STRONG&gt;WARNING: dummy_totweight is not in the report definition.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV id="sasLogWarning2_1574224281024" class="sasWarning"&gt;&lt;FONT face="courier new,courier" color="#339966"&gt;&lt;STRONG&gt;WARNING: weightCustomSubotal is not in the report definition.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;&lt;FONT color="#0000FF"&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;NOTE: Groups are not created because the usage of Name is DISPLAY. To avoid this note, change all GROUP variables to ORDER&amp;nbsp;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;variables.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;The note tells you one of the fixes -- you have to change the usage of SEX to ORDER (not group) so you can do break processing.&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;I think you might be trying to calculate the percent of the Grand Total (which you will get from PCTSUM) and the percent of the sub-group total for each value of SEX. I can't take screen shots right now, but try this code and see if it gets you closer.&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;Cynthia&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options missing=' ';
   PROC REPORT DATA=SASHELP.CLASS out=repout; 
    column SEX NAME AGE WEIGHT weight=wpct  subtot subpct;
    DEFINE SEX / order;
    define weight / analysis sum;
    define wpct / analysis PCTSUM 'pctsum of grand tot' f=percent9.2; 
    define subtot / computed 'subtotal for group';
    define subpct / computed 'pct of subgrp' f=percent9.2;
    compute before sex;
      holdsub = weight.sum;
    endcomp;
    compute subpct;  
      subtot = holdsub;
      subpct = weight.sum /holdsub;
      if upcase(_break_) = '_RBREAK_'  
          then subpct = .;
    endcomp;
    compute after sex;
      name = 'SubTot';
     endcomp;
     compute after;
       name = 'GrandTot';
       subtot = .;
     endcomp;
     BREAK AFTER SEX / SUMMARIZE;
     rbreak after / summarize;

    RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/DIV&gt;</description>
      <pubDate>Wed, 20 Nov 2019 05:40:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Calculate-grand-total-in-subtotal-row/m-p/605622#M17227</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2019-11-20T05:40:16Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate grand total in subtotal row</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Calculate-grand-total-in-subtotal-row/m-p/605734#M17271</link>
      <description>&lt;P&gt;Cynthia,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks a lot for your reply! Your solution does work, the key in your code that I was missing is to create a hold variable in the compute before&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a simplified version of your code that calculates only the column that I need&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options missing=' ';
   PROC REPORT DATA=SASHELP.CLASS out=repout; 
    column sex name weight weightCustomSubtotal;
	define sex / order;
    define weight / noprint;
    compute before;
    	holdtotal = weight.sum;
	    endcomp;
    compute weightCustomSubtotal; 
		if _BREAK_ = 'Sex' THEN
	    	weightCustomSubtotal = holdtotal;
		else 
			weightCustomSubtotal = weight.sum;
 		endcomp;
    BREAK AFTER SEX / SUMMARIZE;
    RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;By the way, if I change sex from ORDER to GROUP it also works with no warnings. At least in SAS 9.4. See the code below&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options missing=' ';
   PROC REPORT DATA=SASHELP.CLASS out=repout; 
    column sex name weight weightCustomSubtotal;
	define sex / group;
    define weight / noprint;
    compute before;
    	holdtotal = weight.sum;
	    endcomp;
    compute weightCustomSubtotal; 
		if _BREAK_ = 'Sex' THEN
	    	weightCustomSubtotal = holdtotal;
		else 
			weightCustomSubtotal = weight.sum;
 		endcomp;
    BREAK AFTER SEX / SUMMARIZE;
    RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Nov 2019 14:49:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Calculate-grand-total-in-subtotal-row/m-p/605734#M17271</guid>
      <dc:creator>HGimenez</dc:creator>
      <dc:date>2019-11-20T14:49:58Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate grand total in subtotal row</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Calculate-grand-total-in-subtotal-row/m-p/605755#M17282</link>
      <description>&lt;P&gt;Hi:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; When I run in 9.4M6, I still see a NOTE with the SAME message. You got rid of the WARNINGS by fixing the COLUMN statement. Here's my log:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="still_gen_note.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/34109iB80532C0F74EBE95/image-size/large?v=v2&amp;amp;px=999" role="button" title="still_gen_note.png" alt="still_gen_note.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Do you see that NOTE? This is still something that you should consider fixing. When you have NAME in the report definition, you are NOT really "grouping" or collapsing rows. You are ORDERing the rows based on the value of the ORDER variable. And, yes, that treats each value of SEX as an ORDERed set --- for the purpose of BREAK processing. But in your usage scenario, the correct usage is ORDER.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cynthia&lt;/P&gt;</description>
      <pubDate>Wed, 20 Nov 2019 14:53:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Calculate-grand-total-in-subtotal-row/m-p/605755#M17282</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2019-11-20T14:53:21Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate grand total in subtotal row</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Calculate-grand-total-in-subtotal-row/m-p/605852#M17306</link>
      <description>Cynthia, thanks again for your reply&lt;BR /&gt;&lt;BR /&gt;No - I don't get that note&lt;BR /&gt;&lt;BR /&gt;I am using&lt;BR /&gt;&lt;BR /&gt;SAS Enterprise Guide version: 7.15 HF7 (7.100.5.6177)&lt;BR /&gt;SAS System version: 9406.100.23523.40334&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 20 Nov 2019 17:46:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Calculate-grand-total-in-subtotal-row/m-p/605852#M17306</guid>
      <dc:creator>HGimenez</dc:creator>
      <dc:date>2019-11-20T17:46:18Z</dc:date>
    </item>
  </channel>
</rss>

