<?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 Spanning headers in PROC TABULATE in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Spanning-headers-in-PROC-TABULATE/m-p/805564#M81706</link>
    <description>&lt;P&gt;I have a request from a customer to produce a report that has two row variables and one column variable and they want the value of the first row variable to span all the columns of the report, rather than be in the first row.&amp;nbsp; They would prefer using TABULATE, but I don't know if it's possible. This little example demonstrates what they want.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc tabulate data=sashelp.shoes;&lt;BR /&gt;where region in ('Asia', 'Canada') and product in ('Boot','Slipper') and Subsidiary in('Montreal','Toronto','Seoul','Bangkok');&lt;BR /&gt;class product region Subsidiary;&lt;BR /&gt;var sales;&lt;BR /&gt;table region=''*(subsidiary='' all='Total'),(product='' all='Total')*(sales=''*sum=''*format=comma8.);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This produces this result:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="PeteLund_0-1648841806106.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/70037i5D44F0D853E0396E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="PeteLund_0-1648841806106.png" alt="PeteLund_0-1648841806106.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What they would like is for the first column to go away and have the value span the rest of the columns, producing something like this instead:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="PeteLund_1-1648841913325.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/70038i330983CBE6570160/image-size/medium?v=v2&amp;amp;px=400" role="button" title="PeteLund_1-1648841913325.png" alt="PeteLund_1-1648841913325.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 01 Apr 2022 19:39:58 GMT</pubDate>
    <dc:creator>PeteLund</dc:creator>
    <dc:date>2022-04-01T19:39:58Z</dc:date>
    <item>
      <title>Spanning headers in PROC TABULATE</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Spanning-headers-in-PROC-TABULATE/m-p/805564#M81706</link>
      <description>&lt;P&gt;I have a request from a customer to produce a report that has two row variables and one column variable and they want the value of the first row variable to span all the columns of the report, rather than be in the first row.&amp;nbsp; They would prefer using TABULATE, but I don't know if it's possible. This little example demonstrates what they want.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc tabulate data=sashelp.shoes;&lt;BR /&gt;where region in ('Asia', 'Canada') and product in ('Boot','Slipper') and Subsidiary in('Montreal','Toronto','Seoul','Bangkok');&lt;BR /&gt;class product region Subsidiary;&lt;BR /&gt;var sales;&lt;BR /&gt;table region=''*(subsidiary='' all='Total'),(product='' all='Total')*(sales=''*sum=''*format=comma8.);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This produces this result:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="PeteLund_0-1648841806106.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/70037i5D44F0D853E0396E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="PeteLund_0-1648841806106.png" alt="PeteLund_0-1648841806106.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What they would like is for the first column to go away and have the value span the rest of the columns, producing something like this instead:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="PeteLund_1-1648841913325.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/70038i330983CBE6570160/image-size/medium?v=v2&amp;amp;px=400" role="button" title="PeteLund_1-1648841913325.png" alt="PeteLund_1-1648841913325.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Apr 2022 19:39:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Spanning-headers-in-PROC-TABULATE/m-p/805564#M81706</guid>
      <dc:creator>PeteLund</dc:creator>
      <dc:date>2022-04-01T19:39:58Z</dc:date>
    </item>
    <item>
      <title>Re: Spanning headers in PROC TABULATE</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Spanning-headers-in-PROC-TABULATE/m-p/805568#M81707</link>
      <description>&lt;P&gt;Would the customer accept a PROC REPORT solution instead of a PROC TABULATE solution?&lt;BR /&gt;In the former, that can be done easily!&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Fri, 01 Apr 2022 20:00:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Spanning-headers-in-PROC-TABULATE/m-p/805568#M81707</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2022-04-01T20:00:34Z</dc:date>
    </item>
    <item>
      <title>Re: Spanning headers in PROC TABULATE</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Spanning-headers-in-PROC-TABULATE/m-p/805570#M81708</link>
      <description>&lt;P&gt;I've mentioned that to them already, along with the data step report writing interface.&amp;nbsp; I will probably end up going with one of those solutions.&amp;nbsp; But, it's been 15+ years since I did anything with TABULATE and didn't want to give up without checking for anyone having a creative solution.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Apr 2022 20:22:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Spanning-headers-in-PROC-TABULATE/m-p/805570#M81708</guid>
      <dc:creator>PeteLund</dc:creator>
      <dc:date>2022-04-01T20:22:39Z</dc:date>
    </item>
    <item>
      <title>Re: Spanning headers in PROC TABULATE</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Spanning-headers-in-PROC-TABULATE/m-p/805574#M81709</link>
      <description>&lt;P&gt;The row heading part can be done with a Multilabel format and suppressing the default heading using Variablename=' ' in the table. The tricky part with Tabulate would suppressing all the statistics on the top row of each group if that is actually desired.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am including an example of multilabel formats and code as a an example. The specific things the provided code were intended to demonstrate was indentation but that is easy to remove if desired. There details between the definition of the format and the options in Tabulate to display though. The code provides a small data set play well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;/* To demonstrate how the order of definition affects appearance in
   multilabel formats. Also appearance options to show the spaces to
   get the indent as desired and fix column widths.
*/
proc format library=work;
value accidentl (multilabel notsorted)
1-5 = 'Accidents'
1-3 = ' Transport accidents'
1 = '   Motor vehicle accidents'
2 = '   Water, air, and space'
3 = '   Other land transport accidents'
4-5 = ' Nontransport accidents'
5 = '   Fishing'
;
value accidentr (multilabel notsorted)
1-5 = 'Accidents'
1-3 = ' Transport accidents'
4-5 = ' Nontransport accidents'
1 = '   Motor vehicle accidents'
2 = '   Water, air, and space'
3 = '   Other land transport accidents'
5 = '   Fishing'
;
value accidents (multilabel notsorted)
1 = '   Motor vehicle accidents'
2 = '   Water, air, and space'
3 = '   Other land transport accidents'
5 = '   Fishing'
1-5 = 'Accidents'
1-3 = ' Transport accidents'
4-5 = ' Nontransport accidents'
;
value mf
1 = "Male"
2 = "Female"
;
value mycolor
1='white'
2='red'
3='green'
4='blue'
5='orange'
6='purple'
;
value accsimple
1 = 'Motor vehicle accidents'
2 = 'Water, air, and space'
3 = 'Other land transport accidents'
4 = 'Nontransport accidents'
5 = 'Fishing'
;
value MyColorl (multilabel notsorted)
1-5 = 'white'
1-3 = 'red'
1 = 'blue'
2 = 'orange'
3 = 'pink'
4-5 = 'purple'
5 = 'black'
;
run;

/* populate a dataset to display */
/* This specifically does NOT generate any data for FISHING above*/
/* to display the behavior of the options below in those cases. */
data junk; 
do i=1 to 50;
type = round(4*ranuni(1234)+.5);
sex = round(2*ranuni(3455)+.5);
output;
end; 
run;


/* Notice that before we get here the data is NOT sorted */
/* in any manner!!!! */
title 'Option Order=Data Preloadfmt Printmiss Misstext=0 format accidentl';
proc tabulate data=junk order=data ;
   class type / mlf PRELOADFMT;
   /*ASIS preserves the leading spaces in the format, Cellwidth here is optional
     for this demo. These will ONLY affect ODS output such as HTML, RTF or PDF
     not the OUTPUT window
  */
   classlev type/ style=[asis=on cellwidth=1.5in];
   class sex;
   /* the formatted values of SEX normally take up different lengths, this fixes
      the column widths to be the same for both headers. May cause interesting
      appearances with large numbers of displayed digits if requested in formats*/
   classlev sex/ style=[cellwidth=.5in];
   /* to get the ALL to have the same width as SEX need to specify this way*/
   table type=' ', all='Total'*{style=[cellwidth=.5in]}*n=' '*f=comma9. sex=' '*n=' '*f=comma8.
   / printmiss misstext='0';
   format type accidentl. sex mf.;
run;title;

title 'Option simple format and classlev background color';
proc tabulate data=junk order=data ;
   class type / ;
   /*ASIS preserves the leading spaces in the format, Cellwidth here is optional
     for this demo. These will ONLY affect ODS output such as HTML, RTF or PDF
     not the OUTPUT window
  */
   classlev type/ style=[asis=on cellwidth=1.5in background=mycolor.];
   class sex;
   /* the formatted values of SEX normally take up different lengths, this fixes
      the column widths to be the same for both headers. May cause interesting
      appearances with large numbers of displayed digits if requested in formats*/
   classlev sex/ style=[cellwidth=.5in];
   /* to get the ALL to have the same width as SEX need to specify this way*/
   table type=' ', all='Total'*{style=[cellwidth=.5in]}*n=' '*f=comma9. sex=' '*n=' '*f=comma8.
   / row=float misstext='0';
   format type accsimple. sex mf.;
run;title;

title 'Option Order=Data Preloadfmt Printmiss Misstext=0 format accidentl classlev background';
proc tabulate data=junk order=data;
   class type / mlf PRELOADFMT;
   classlev type/ style=[asis=on cellwidth=1.5in background=mycolor.];
   class sex;
   classlev sex/ style=[cellwidth=.5in];
   table type=' ', all='Total'*{style=[cellwidth=.5in]}*n=' '*f=comma9. sex=' '*n=' '*f=comma8.
   / printmiss misstext='0';
   format type accidentl. sex mf.;
run;title;
title 'Option Order=Data Preloadfmt Printmiss Misstext=0 format accidents';
proc tabulate data=junk order=data;
   class type / mlf PRELOADFMT;
   classlev type/ style=[asis=on cellwidth=1.5in];
   class sex;
   classlev sex/ style=[cellwidth=.5in];
   table type=' ', all='Total'*{style=[cellwidth=.5in]}*n=' '*f=comma9. sex=' '*n=' '*f=comma8.
   / printmiss misstext='0';
   format type accidents. sex mf.;
run;title;
 

&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 02 Apr 2022 14:57:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Spanning-headers-in-PROC-TABULATE/m-p/805574#M81709</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-04-02T14:57:16Z</dc:date>
    </item>
    <item>
      <title>Re: Spanning headers in PROC TABULATE</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Spanning-headers-in-PROC-TABULATE/m-p/805616#M81710</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc report data=sashelp.shoes nowd;
where region in ('Asia', 'Canada') and product in ('Boot','Slipper') and Subsidiary in('Montreal','Toronto','Seoul','Bangkok');
columns  region Subsidiary   sales,product sales=s;
define  region/group noprint;
define Subsidiary /group ' ' ;
define product/across ' ';
define sales/analysis sum ' ' format=comma32.;
define s/analysis sum 'Total'  format=comma32.;
compute after region;
Subsidiary='Total';
endcomp;
compute before region/style=header{just=l};
line region $80.;
endcomp; 
break after region/summarize  ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_0-1648899756889.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/70053iEFF77D3E3A1A3309/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1648899756889.png" alt="Ksharp_0-1648899756889.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 02 Apr 2022 11:42:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Spanning-headers-in-PROC-TABULATE/m-p/805616#M81710</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-04-02T11:42:45Z</dc:date>
    </item>
  </channel>
</rss>

