<?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 Tabulate to mirror pivot table in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Tabulate-to-mirror-pivot-table/m-p/837719#M82127</link>
    <description>Another alternative is to pipe the output to a table, sort using PROC SORT and then display using PROC REPORT.</description>
    <pubDate>Mon, 10 Oct 2022 18:26:28 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2022-10-10T18:26:28Z</dc:date>
    <item>
      <title>Proc Tabulate to mirror pivot table</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Tabulate-to-mirror-pivot-table/m-p/837445#M82118</link>
      <description>&lt;P&gt;Hello.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have create this code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc tabulate data=sashelp.cars;&lt;BR /&gt;class Origin DriveTrain;&lt;BR /&gt;table Origin * (DriveTrain all="Sub Total") all="Grand Total", all*n;&lt;BR /&gt;keylabel n='Number of each Drive Train';&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Which gives me this:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SYLC_0-1665163980170.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/76019iAFDFA12456219BB3/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SYLC_0-1665163980170.png" alt="SYLC_0-1665163980170.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;But how do I sort the all, front and rear in descending order for each drivetrain like it does in excel pivot table below:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SYLC_1-1665164084539.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/76020iC1700E0DF39C9E65/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SYLC_1-1665164084539.png" alt="SYLC_1-1665164084539.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Oct 2022 17:35:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-Tabulate-to-mirror-pivot-table/m-p/837445#M82118</guid>
      <dc:creator>SYLC</dc:creator>
      <dc:date>2022-10-07T17:35:58Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Tabulate to mirror pivot table</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Tabulate-to-mirror-pivot-table/m-p/837453#M82120</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;proc tabulate data=sashelp.cars;
   class Origin;
   class DriveTrain&lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;/ order=freq&lt;/STRONG&gt;&lt;/FONT&gt;;
   table Origin * (all="Sub Total" DriveTrain ) all="Grand Total", all*n;
   keylabel n='Number of each Drive Train';
run;&lt;/PRE&gt;
&lt;P&gt;I moved the All for the Drivetrain subtotal to have the total appear a the top if you want that behavior from the "pivot" as well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Caution: the order=freq can get tricky with nested variables in complex tables.&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/400836"&gt;@SYLC&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have create this code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc tabulate data=sashelp.cars;&lt;BR /&gt;class Origin DriveTrain;&lt;BR /&gt;table Origin * (DriveTrain all="Sub Total") all="Grand Total", all*n;&lt;BR /&gt;keylabel n='Number of each Drive Train';&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Which gives me this:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SYLC_0-1665163980170.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/76019iAFDFA12456219BB3/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SYLC_0-1665163980170.png" alt="SYLC_0-1665163980170.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;But how do I sort the all, front and rear in descending order for each drivetrain like it does in excel pivot table below:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SYLC_1-1665164084539.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/76020iC1700E0DF39C9E65/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SYLC_1-1665164084539.png" alt="SYLC_1-1665164084539.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Thanks in advance.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Oct 2022 19:05:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-Tabulate-to-mirror-pivot-table/m-p/837453#M82120</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-10-07T19:05:10Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Tabulate to mirror pivot table</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Tabulate-to-mirror-pivot-table/m-p/837459#M82123</link>
      <description>FYI - you should probably remove all from your pivot table as it double counts if you're using that Excel for anything.</description>
      <pubDate>Fri, 07 Oct 2022 20:11:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-Tabulate-to-mirror-pivot-table/m-p/837459#M82123</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-10-07T20:11:40Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Tabulate to mirror pivot table</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Tabulate-to-mirror-pivot-table/m-p/837625#M82125</link>
      <description>&lt;P&gt;Thanks. I see what you mean by tricky. For the most part it has work but there are a few rows out of sequence.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I guess the alternative would be to create a table from scratch using the count function.&lt;/P&gt;</description>
      <pubDate>Mon, 10 Oct 2022 09:51:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-Tabulate-to-mirror-pivot-table/m-p/837625#M82125</guid>
      <dc:creator>SYLC</dc:creator>
      <dc:date>2022-10-10T09:51:16Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Tabulate to mirror pivot table</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Tabulate-to-mirror-pivot-table/m-p/837719#M82127</link>
      <description>Another alternative is to pipe the output to a table, sort using PROC SORT and then display using PROC REPORT.</description>
      <pubDate>Mon, 10 Oct 2022 18:26:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-Tabulate-to-mirror-pivot-table/m-p/837719#M82127</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-10-10T18:26:28Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Tabulate to mirror pivot table</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Tabulate-to-mirror-pivot-table/m-p/837943#M82133</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc tabulate data=sashelp.cars;
class Origin DriveTrain /order=freq;
table Origin * (DriveTrain all="Sub Total") all="Grand Total" , all=''*n 
  / Box='Origin and Drive Train';
keylabel n='Number of each Drive Train';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ghosh_0-1665521210170.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/76097iDEE512D8F3809FD4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ghosh_0-1665521210170.png" alt="ghosh_0-1665521210170.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Oct 2022 20:47:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-Tabulate-to-mirror-pivot-table/m-p/837943#M82133</guid>
      <dc:creator>ghosh</dc:creator>
      <dc:date>2022-10-11T20:47:16Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Tabulate to mirror pivot table</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-Tabulate-to-mirror-pivot-table/m-p/838018#M82134</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Very interesting question.
Hope SAS could have an option to handle this sitation.*/
proc freq data=sashelp.cars noprint ;
table Origin*DriveTrain/out=classdata ;
run;
proc sort data=classdata;by Origin descending count;run;
data classdata;
length DriveTrain $ 100;
 set classdata;
 by Origin;
n+first.Origin;
DriveTrain=repeat(' ',n)||DriveTrain;
drop n;
run;



proc tabulate data=classdata  format=best. ;
class Origin DriveTrain/order=data;
var count;
table Origin * (DriveTrain all="Sub Total") all="Grand Total", all*count="Number of each Drive Train"*sum="";
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-1665574963303.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/76108i98E064B64334A44F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1665574963303.png" alt="Ksharp_0-1665574963303.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Oct 2022 11:42:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-Tabulate-to-mirror-pivot-table/m-p/838018#M82134</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-10-12T11:42:20Z</dc:date>
    </item>
  </channel>
</rss>

