<?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: Proc Report How to format heading / add labels in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Report-How-to-format-heading-add-labels/m-p/502034#M72697</link>
    <description>&lt;P&gt;Well, changing your data structure slightly makes this a lot simpler. That's the first step I do, make it a long data set so TYPE is a variable that holds values of A/B and add a variable called VALUE that holds the amounts.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's the PROC TABULATE solution. Notice the use of the ALL keywords that control which totals you get and where they go. If you put ALL before the variable name for example, totals will be your first row.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data long;
set tabletest;
Type='A';
Value = typeA;
output;
Type='B';
value = typeB;
output;
drop typeA typeB;
run;

proc tabulate data=long;
class referral_total referral_source type;

var value;
table (referral_total*(referral_source all) all), (type all)*value=''*sum=''*f=8.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Here's a decent paper on the topic if you need to understand the details or what anything in particular is doing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/resources/papers/proceedings11/260-2011.pdf" target="_blank"&gt;http://support.sas.com/resources/papers/proceedings11/260-2011.pdf&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 05 Oct 2018 19:42:19 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2018-10-05T19:42:19Z</dc:date>
    <item>
      <title>Proc Report How to format heading / add labels</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Report-How-to-format-heading-add-labels/m-p/502021#M72694</link>
      <description>&lt;P&gt;I have some data that looks like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data tabletest;&lt;BR /&gt;informat referral_total $50. referral_source $20.;&lt;BR /&gt;infile datalines delimiter='|';&lt;BR /&gt;input referral_total referral_source TypeA TypeB ;&lt;BR /&gt;datalines;&lt;BR /&gt;Long Org Name | SubA | 12 | 5&lt;BR /&gt;Long Org Name | SubB | 14 | 3&lt;BR /&gt;Longer Org Name | SubC | 0 | 1&lt;BR /&gt;Longer Org Name | SubD | 4 | 12&lt;BR /&gt;Very Long Org | SubE | 3 | 11&lt;BR /&gt;Very Long Org | SubF | 9 | 19&lt;BR /&gt;Very Long Org | SubG | 1 | 22&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have some preliminary code to add subtotals by the referral_total values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc report data=tabletest nofs headline headskip;&lt;BR /&gt;column referral_total referral_source TypeA TypeB;&lt;BR /&gt;define referral_total / group ;&lt;BR /&gt;define referral_source / group;&lt;BR /&gt;define TypeA / sum ' ';&lt;BR /&gt;define TypeB / sum ' ';&lt;BR /&gt;break after referral_total / summarize style={background=lightblue font_weight=bold };&lt;BR /&gt;rbreak after /summarize;&lt;BR /&gt;compute referral_total;&lt;BR /&gt; if _break_ = 'referral_total' then&lt;BR /&gt; do;&lt;BR /&gt; referral_total = catx(' ', referral_total, 'Total');&lt;BR /&gt; end;&lt;BR /&gt;else if _break_ in ('_RBREAK_') then&lt;BR /&gt; do;&lt;BR /&gt; referral_total='Total';&lt;BR /&gt; end;&lt;BR /&gt;endcomp;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. How do I add a column that is a sum of TypeA + TypeB?&amp;nbsp; This would be named Total Referrals.&lt;/P&gt;
&lt;P&gt;2. How do I change and format the labels of the header in the table? (see example desired output)&lt;/P&gt;
&lt;P&gt;&amp;nbsp; -Add a spanned row with the Table Title&lt;/P&gt;
&lt;P&gt;&amp;nbsp; -Have Referral Source, Number of A, Number of B as columns with the correct labels and not the name of the variable from the dataset.&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;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="tableexample.PNG" style="width: 503px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/23826i7E07B14633616AE6/image-size/large?v=v2&amp;amp;px=999" role="button" title="tableexample.PNG" alt="tableexample.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Oct 2018 19:02:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-Report-How-to-format-heading-add-labels/m-p/502021#M72694</guid>
      <dc:creator>appleorange</dc:creator>
      <dc:date>2018-10-05T19:02:48Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Report How to format heading / add labels</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Report-How-to-format-heading-add-labels/m-p/502025#M72695</link>
      <description>&lt;P&gt;PROC TABULATE does a lot this by default. Are you set on using PROC REPORT?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/37299"&gt;@appleorange&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have some data that looks like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data tabletest;&lt;BR /&gt;informat referral_total $50. referral_source $20.;&lt;BR /&gt;infile datalines delimiter='|';&lt;BR /&gt;input referral_total referral_source TypeA TypeB ;&lt;BR /&gt;datalines;&lt;BR /&gt;Long Org Name | SubA | 12 | 5&lt;BR /&gt;Long Org Name | SubB | 14 | 3&lt;BR /&gt;Longer Org Name | SubC | 0 | 1&lt;BR /&gt;Longer Org Name | SubD | 4 | 12&lt;BR /&gt;Very Long Org | SubE | 3 | 11&lt;BR /&gt;Very Long Org | SubF | 9 | 19&lt;BR /&gt;Very Long Org | SubG | 1 | 22&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have some preliminary code to add subtotals by the referral_total values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc report data=tabletest nofs headline headskip;&lt;BR /&gt;column referral_total referral_source TypeA TypeB;&lt;BR /&gt;define referral_total / group ;&lt;BR /&gt;define referral_source / group;&lt;BR /&gt;define TypeA / sum ' ';&lt;BR /&gt;define TypeB / sum ' ';&lt;BR /&gt;break after referral_total / summarize style={background=lightblue font_weight=bold };&lt;BR /&gt;rbreak after /summarize;&lt;BR /&gt;compute referral_total;&lt;BR /&gt; if _break_ = 'referral_total' then&lt;BR /&gt; do;&lt;BR /&gt; referral_total = catx(' ', referral_total, 'Total');&lt;BR /&gt; end;&lt;BR /&gt;else if _break_ in ('_RBREAK_') then&lt;BR /&gt; do;&lt;BR /&gt; referral_total='Total';&lt;BR /&gt; end;&lt;BR /&gt;endcomp;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. How do I add a column that is a sum of TypeA + TypeB?&amp;nbsp; This would be named Total Referrals.&lt;/P&gt;
&lt;P&gt;2. How do I change and format the labels of the header in the table? (see example desired output)&lt;/P&gt;
&lt;P&gt;&amp;nbsp; -Add a spanned row with the Table Title&lt;/P&gt;
&lt;P&gt;&amp;nbsp; -Have Referral Source, Number of A, Number of B as columns with the correct labels and not the name of the variable from the dataset.&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;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="tableexample.PNG" style="width: 503px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/23826i7E07B14633616AE6/image-size/large?v=v2&amp;amp;px=999" role="button" title="tableexample.PNG" alt="tableexample.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Oct 2018 19:24:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-Report-How-to-format-heading-add-labels/m-p/502025#M72695</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-10-05T19:24:09Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Report How to format heading / add labels</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Report-How-to-format-heading-add-labels/m-p/502029#M72696</link>
      <description>&lt;P&gt;I think so?&amp;nbsp; I'm relatively new to proc report/tabulate, but this table will be one of many tables in a report with ODS formatting to PDF.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Oct 2018 19:30:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-Report-How-to-format-heading-add-labels/m-p/502029#M72696</guid>
      <dc:creator>appleorange</dc:creator>
      <dc:date>2018-10-05T19:30:19Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Report How to format heading / add labels</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Report-How-to-format-heading-add-labels/m-p/502034#M72697</link>
      <description>&lt;P&gt;Well, changing your data structure slightly makes this a lot simpler. That's the first step I do, make it a long data set so TYPE is a variable that holds values of A/B and add a variable called VALUE that holds the amounts.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's the PROC TABULATE solution. Notice the use of the ALL keywords that control which totals you get and where they go. If you put ALL before the variable name for example, totals will be your first row.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data long;
set tabletest;
Type='A';
Value = typeA;
output;
Type='B';
value = typeB;
output;
drop typeA typeB;
run;

proc tabulate data=long;
class referral_total referral_source type;

var value;
table (referral_total*(referral_source all) all), (type all)*value=''*sum=''*f=8.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Here's a decent paper on the topic if you need to understand the details or what anything in particular is doing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/resources/papers/proceedings11/260-2011.pdf" target="_blank"&gt;http://support.sas.com/resources/papers/proceedings11/260-2011.pdf&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Oct 2018 19:42:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-Report-How-to-format-heading-add-labels/m-p/502034#M72697</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-10-05T19:42:19Z</dc:date>
    </item>
  </channel>
</rss>

