<?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 Weighted and Unweighted Sums in Same Table in ODS and Base Reporting</title>
    <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Weighted-and-Unweighted-Sums-in-Same-Table/m-p/555452#M22713</link>
    <description>&lt;P&gt;I have a need to produce some tables that show the weighted and unweighted sums of a number of numerical variables, crossed by a categorical variable, with the output going to Excel.&amp;nbsp; See the table shell below.&amp;nbsp; I know that I can produce these sums separately, save them to one or more datasets, and then reshape the data before sending it to Excel.&amp;nbsp; I was wondering if there was any capability in PROC TABULATE or PROC REPORT that would allow me to do this directly.&amp;nbsp;&amp;nbsp;&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="Capture.PNG" style="width: 594px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/29152i09347EA8E441E32A/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 01 May 2019 19:08:40 GMT</pubDate>
    <dc:creator>Davanden</dc:creator>
    <dc:date>2019-05-01T19:08:40Z</dc:date>
    <item>
      <title>Weighted and Unweighted Sums in Same Table</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Weighted-and-Unweighted-Sums-in-Same-Table/m-p/555452#M22713</link>
      <description>&lt;P&gt;I have a need to produce some tables that show the weighted and unweighted sums of a number of numerical variables, crossed by a categorical variable, with the output going to Excel.&amp;nbsp; See the table shell below.&amp;nbsp; I know that I can produce these sums separately, save them to one or more datasets, and then reshape the data before sending it to Excel.&amp;nbsp; I was wondering if there was any capability in PROC TABULATE or PROC REPORT that would allow me to do this directly.&amp;nbsp;&amp;nbsp;&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="Capture.PNG" style="width: 594px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/29152i09347EA8E441E32A/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 01 May 2019 19:08:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Weighted-and-Unweighted-Sums-in-Same-Table/m-p/555452#M22713</guid>
      <dc:creator>Davanden</dc:creator>
      <dc:date>2019-05-01T19:08:40Z</dc:date>
    </item>
    <item>
      <title>Re: Weighted and Unweighted Sums in Same Table</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Weighted-and-Unweighted-Sums-in-Same-Table/m-p/555458#M22714</link>
      <description>&lt;P&gt;I would do this in PROC SUMMARY, which will create the weighted sums and unweighted sums, it will also create the columns that you have labelled "ALL", and then use the output data set from PROC SUMMARY as the input to PROC REPORT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's an example using the data set SASHELP.CLASS&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=sashelp.class;
    class sex age;
	var weight/weight=height;
	output out=results1 sum=weighted_sum;
run;

proc summary data=sashelp.class;
    class sex age;
	var weight;
	output out=results2 sum=unweighted_sum;
run;
proc format;
    value $sf 'Z'='All';
    value agef 999='All';
run;
data results;
	merge results1 results2;
	if missing(sex) then sex='Z';
	if missing(age) then age=999;
        format sex $sf. age agef.;
run;


proc report data=results;
	columns sex age,weighted_sum age,unweighted_sum;
	define sex/group;
	define age/across;
	define weighted_sum/analysis sum;
	define unweighted_sum/analysis sum;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 01 May 2019 19:36:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Weighted-and-Unweighted-Sums-in-Same-Table/m-p/555458#M22714</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-05-01T19:36:17Z</dc:date>
    </item>
    <item>
      <title>Re: Weighted and Unweighted Sums in Same Table</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Weighted-and-Unweighted-Sums-in-Same-Table/m-p/555462#M22715</link>
      <description>&lt;P&gt;Create a view with a duplicate copy of the variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bad example but this illustrates the concept:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have / view=have;
set sashelp.class;
Height2 = Height;
run;

proc tabulate data=have;
class sex  name;
var height;
var height2 / weight = age;

table sex , name* (height*sum height2*sum);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 01 May 2019 19:42:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Weighted-and-Unweighted-Sums-in-Same-Table/m-p/555462#M22715</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-05-01T19:42:31Z</dc:date>
    </item>
    <item>
      <title>Re: Weighted and Unweighted Sums in Same Table</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Weighted-and-Unweighted-Sums-in-Same-Table/m-p/555586#M22716</link>
      <description>Thank you for your reply. I am already doing something similar to what you suggest, except that I am using TABULATE to produce the two sets of sums, sending the output to datasets.&lt;BR /&gt;</description>
      <pubDate>Thu, 02 May 2019 12:30:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Weighted-and-Unweighted-Sums-in-Same-Table/m-p/555586#M22716</guid>
      <dc:creator>Davanden</dc:creator>
      <dc:date>2019-05-02T12:30:17Z</dc:date>
    </item>
    <item>
      <title>Re: Weighted and Unweighted Sums in Same Table</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Weighted-and-Unweighted-Sums-in-Same-Table/m-p/555588#M22717</link>
      <description>Thank you for this. That works in principle. I have a large number of such tables to construct, with many combinations of variables. I'll have to think about whether this approach really reduces the complexity.&lt;BR /&gt;&lt;BR /&gt;Incidentally, in my years of writing SAS code, I never noticed that the VAR statement had the /WEIGHT option. So I learned something useful!&lt;BR /&gt;</description>
      <pubDate>Thu, 02 May 2019 12:34:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Weighted-and-Unweighted-Sums-in-Same-Table/m-p/555588#M22717</guid>
      <dc:creator>Davanden</dc:creator>
      <dc:date>2019-05-02T12:34:17Z</dc:date>
    </item>
  </channel>
</rss>

