<?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 a column from a summary table in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Calculate-a-column-from-a-summary-table/m-p/33159#M8038</link>
    <description>Hi:&lt;BR /&gt;
  The question is: what is your procedure of choice? What are you currently using to create the summary table?&lt;BR /&gt;
&lt;BR /&gt;
  If you are using PROC FREQ or PROC TABULATE or PROC MEANS to create your summary table, then the answer is NO, you cannot make a calculation based on summary columns unless you create an output dataset and then use that dataset within a program that does the calculation.&lt;BR /&gt;
&lt;BR /&gt;
  However, PROC REPORT, using a COMPUTE block, can create calculated columns using existing report columns. As shown in the program below. For more information on PROC REPORT, you might consult these sites:&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/onlinedoc/v82/techreport_p258.pdf" target="_blank"&gt;http://support.sas.com/documentation/onlinedoc/v82/techreport_p258.pdf&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://support.sas.com/rnd/papers/sgf07/sgf2007-report.pdf" target="_blank"&gt;http://support.sas.com/rnd/papers/sgf07/sgf2007-report.pdf&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/proc/59565/HTML/default/report-overview.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/proc/59565/HTML/default/report-overview.htm&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
PROC REPORT can create cross-tabular reports too. The computations with ACROSS variables are do-able, but you need to use the "absolute" column names for the ACROSS vars, instead of the dataset name. That's because each report column that comes from an ACROSS usage gets a unique number of its own. The second document above shows an example of doing this. &lt;BR /&gt;
cynthia&lt;BR /&gt;
[pre]&lt;BR /&gt;
ods html file='c:\temp\compute_examp.html' style=sasweb;&lt;BR /&gt;
  proc report data=sashelp.prdsale nowd;&lt;BR /&gt;
    column division prodtype n actual predict diff;&lt;BR /&gt;
    define division / group;&lt;BR /&gt;
    define prodtype / group;&lt;BR /&gt;
    define actual / sum;&lt;BR /&gt;
    define predict / sum;&lt;BR /&gt;
    define n / 'Count of Sales';&lt;BR /&gt;
    define diff / computed f=dollar8.;&lt;BR /&gt;
    rbreak after / summarize;&lt;BR /&gt;
    compute diff;&lt;BR /&gt;
      diff = actual.sum - predict.sum;&lt;BR /&gt;
    endcomp;&lt;BR /&gt;
  run;&lt;BR /&gt;
ods html close;&lt;BR /&gt;
[/pre]</description>
    <pubDate>Tue, 22 Jul 2008 15:02:49 GMT</pubDate>
    <dc:creator>Cynthia_sas</dc:creator>
    <dc:date>2008-07-22T15:02:49Z</dc:date>
    <item>
      <title>Calculate a column from a summary table</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Calculate-a-column-from-a-summary-table/m-p/33158#M8037</link>
      <description>How do i calculate new columns based on columns in a summary table. I.e I create a summary table which gives  me exactly what i want and how i want to see the data. However i want to make a calculation based on two of the columns in the sumary table.&lt;BR /&gt;
&lt;BR /&gt;
If i output the summary table as a data table the format of the data completly changes. The data table changes the summary table columns into rows.</description>
      <pubDate>Tue, 22 Jul 2008 11:55:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Calculate-a-column-from-a-summary-table/m-p/33158#M8037</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-07-22T11:55:03Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate a column from a summary table</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Calculate-a-column-from-a-summary-table/m-p/33159#M8038</link>
      <description>Hi:&lt;BR /&gt;
  The question is: what is your procedure of choice? What are you currently using to create the summary table?&lt;BR /&gt;
&lt;BR /&gt;
  If you are using PROC FREQ or PROC TABULATE or PROC MEANS to create your summary table, then the answer is NO, you cannot make a calculation based on summary columns unless you create an output dataset and then use that dataset within a program that does the calculation.&lt;BR /&gt;
&lt;BR /&gt;
  However, PROC REPORT, using a COMPUTE block, can create calculated columns using existing report columns. As shown in the program below. For more information on PROC REPORT, you might consult these sites:&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/onlinedoc/v82/techreport_p258.pdf" target="_blank"&gt;http://support.sas.com/documentation/onlinedoc/v82/techreport_p258.pdf&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://support.sas.com/rnd/papers/sgf07/sgf2007-report.pdf" target="_blank"&gt;http://support.sas.com/rnd/papers/sgf07/sgf2007-report.pdf&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/proc/59565/HTML/default/report-overview.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/proc/59565/HTML/default/report-overview.htm&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
PROC REPORT can create cross-tabular reports too. The computations with ACROSS variables are do-able, but you need to use the "absolute" column names for the ACROSS vars, instead of the dataset name. That's because each report column that comes from an ACROSS usage gets a unique number of its own. The second document above shows an example of doing this. &lt;BR /&gt;
cynthia&lt;BR /&gt;
[pre]&lt;BR /&gt;
ods html file='c:\temp\compute_examp.html' style=sasweb;&lt;BR /&gt;
  proc report data=sashelp.prdsale nowd;&lt;BR /&gt;
    column division prodtype n actual predict diff;&lt;BR /&gt;
    define division / group;&lt;BR /&gt;
    define prodtype / group;&lt;BR /&gt;
    define actual / sum;&lt;BR /&gt;
    define predict / sum;&lt;BR /&gt;
    define n / 'Count of Sales';&lt;BR /&gt;
    define diff / computed f=dollar8.;&lt;BR /&gt;
    rbreak after / summarize;&lt;BR /&gt;
    compute diff;&lt;BR /&gt;
      diff = actual.sum - predict.sum;&lt;BR /&gt;
    endcomp;&lt;BR /&gt;
  run;&lt;BR /&gt;
ods html close;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Tue, 22 Jul 2008 15:02:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Calculate-a-column-from-a-summary-table/m-p/33159#M8038</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2008-07-22T15:02:49Z</dc:date>
    </item>
  </channel>
</rss>

