<?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 Proc Report - Subtotal Columns in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Proc-Report-Subtotal-Columns/m-p/927918#M44755</link>
    <description>&lt;P&gt;Hi all - I have a specific report format that I am trying to achieve using PROC REPORT, and I'm getting pretty close, but there's a column subtotal element that I cannot figure out.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have sales data, summarized by Client, Quarter, and Week.&amp;nbsp; Each quarter contains an arbitrary number of weeks, up to around 13.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to list Client information down the side, with:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Quarters listed across the top,&lt;/LI&gt;
&lt;LI&gt;each Quarter's corresponding Weeks nested underneath,&lt;/LI&gt;
&lt;LI&gt;the table populated with Sales for each Client-Week,&lt;/LI&gt;
&lt;LI&gt;and Grand Totals on the far right and bottom.&amp;nbsp; I've gotten this far on my own just fine.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Where I'm getting stuck is that I'd&amp;nbsp;&lt;EM&gt;also&lt;/EM&gt; like to show &lt;STRONG&gt;Quarterly subtotal columns&lt;/STRONG&gt;, at the end of each Quarter.&amp;nbsp; I have tried different variations of "break after" and the like, but I'm just not getting there.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does anyone in the community have any suggestions?&amp;nbsp; Below is some sample code that represents the progress I've made so far.&amp;nbsp; I've also attached an image showing what I currently "have" versus what I "want."&amp;nbsp; I greatly appreciate any and all help - cheers!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data one;&lt;BR /&gt;input client_rank client $9. client_id quarter $ weekending sales;&lt;BR /&gt;datalines;&lt;BR /&gt;1 Apple 12345 Q1 20240106 1000&lt;BR /&gt;1 Apple 12345 Q1 20240113 2000&lt;BR /&gt;1 Apple 12345 Q1 20240127 5000&lt;BR /&gt;1 Apple 12345 Q2 20240413 3000&lt;BR /&gt;1 Apple 12345 Q2 20240420 4000&lt;BR /&gt;1 Apple 12345 Q2 20240427 2000&lt;BR /&gt;2 Microsoft 67890 Q1 20240106 3000&lt;BR /&gt;2 Microsoft 67890 Q1 20240113 1000&lt;BR /&gt;2 Microsoft 67890 Q1 20240127 2500&lt;BR /&gt;2 Microsoft 67890 Q2 20240413 4000&lt;BR /&gt;2 Microsoft 67890 Q2 20240420 500&lt;BR /&gt;2 Microsoft 67890 Q2 20240427 1500&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;proc report data = one nowd;&lt;BR /&gt;column client_rank client client_id quarter, weekending, sales ("Total" sales=tot);&lt;BR /&gt;define client_rank / noprint group;&lt;BR /&gt;define client / "Client" group;&lt;BR /&gt;define client_id / "Client ID" group;&lt;BR /&gt;define quarter / " " across;&lt;BR /&gt;define weekending / " " across nozero;&lt;BR /&gt;define sales / "Sales" analysis sum format=comma12.0;&lt;BR /&gt;define tot / "Sales" analysis sum format=comma12.0;&lt;/P&gt;
&lt;P&gt;rbreak after / summarize;&lt;BR /&gt;compute after;&lt;BR /&gt;client = "Total";&lt;BR /&gt;endcomp;&lt;BR /&gt;define client_rank / order group;&lt;BR /&gt;run;&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="Proc Report Help.jpg" style="width: 731px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/96421iC499528DB7CC4633/image-size/large?v=v2&amp;amp;px=999" role="button" title="Proc Report Help.jpg" alt="Proc Report Help.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 10 May 2024 18:07:23 GMT</pubDate>
    <dc:creator>cbal324</dc:creator>
    <dc:date>2024-05-10T18:07:23Z</dc:date>
    <item>
      <title>Proc Report - Subtotal Columns</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Proc-Report-Subtotal-Columns/m-p/927918#M44755</link>
      <description>&lt;P&gt;Hi all - I have a specific report format that I am trying to achieve using PROC REPORT, and I'm getting pretty close, but there's a column subtotal element that I cannot figure out.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have sales data, summarized by Client, Quarter, and Week.&amp;nbsp; Each quarter contains an arbitrary number of weeks, up to around 13.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to list Client information down the side, with:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Quarters listed across the top,&lt;/LI&gt;
&lt;LI&gt;each Quarter's corresponding Weeks nested underneath,&lt;/LI&gt;
&lt;LI&gt;the table populated with Sales for each Client-Week,&lt;/LI&gt;
&lt;LI&gt;and Grand Totals on the far right and bottom.&amp;nbsp; I've gotten this far on my own just fine.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Where I'm getting stuck is that I'd&amp;nbsp;&lt;EM&gt;also&lt;/EM&gt; like to show &lt;STRONG&gt;Quarterly subtotal columns&lt;/STRONG&gt;, at the end of each Quarter.&amp;nbsp; I have tried different variations of "break after" and the like, but I'm just not getting there.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does anyone in the community have any suggestions?&amp;nbsp; Below is some sample code that represents the progress I've made so far.&amp;nbsp; I've also attached an image showing what I currently "have" versus what I "want."&amp;nbsp; I greatly appreciate any and all help - cheers!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data one;&lt;BR /&gt;input client_rank client $9. client_id quarter $ weekending sales;&lt;BR /&gt;datalines;&lt;BR /&gt;1 Apple 12345 Q1 20240106 1000&lt;BR /&gt;1 Apple 12345 Q1 20240113 2000&lt;BR /&gt;1 Apple 12345 Q1 20240127 5000&lt;BR /&gt;1 Apple 12345 Q2 20240413 3000&lt;BR /&gt;1 Apple 12345 Q2 20240420 4000&lt;BR /&gt;1 Apple 12345 Q2 20240427 2000&lt;BR /&gt;2 Microsoft 67890 Q1 20240106 3000&lt;BR /&gt;2 Microsoft 67890 Q1 20240113 1000&lt;BR /&gt;2 Microsoft 67890 Q1 20240127 2500&lt;BR /&gt;2 Microsoft 67890 Q2 20240413 4000&lt;BR /&gt;2 Microsoft 67890 Q2 20240420 500&lt;BR /&gt;2 Microsoft 67890 Q2 20240427 1500&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;proc report data = one nowd;&lt;BR /&gt;column client_rank client client_id quarter, weekending, sales ("Total" sales=tot);&lt;BR /&gt;define client_rank / noprint group;&lt;BR /&gt;define client / "Client" group;&lt;BR /&gt;define client_id / "Client ID" group;&lt;BR /&gt;define quarter / " " across;&lt;BR /&gt;define weekending / " " across nozero;&lt;BR /&gt;define sales / "Sales" analysis sum format=comma12.0;&lt;BR /&gt;define tot / "Sales" analysis sum format=comma12.0;&lt;/P&gt;
&lt;P&gt;rbreak after / summarize;&lt;BR /&gt;compute after;&lt;BR /&gt;client = "Total";&lt;BR /&gt;endcomp;&lt;BR /&gt;define client_rank / order group;&lt;BR /&gt;run;&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="Proc Report Help.jpg" style="width: 731px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/96421iC499528DB7CC4633/image-size/large?v=v2&amp;amp;px=999" role="button" title="Proc Report Help.jpg" alt="Proc Report Help.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 10 May 2024 18:07:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Proc-Report-Subtotal-Columns/m-p/927918#M44755</guid>
      <dc:creator>cbal324</dc:creator>
      <dc:date>2024-05-10T18:07:23Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Report - Subtotal Columns</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Proc-Report-Subtotal-Columns/m-p/927944#M44756</link>
      <description>&lt;P&gt;Before going on to some possible solutions there are some questions that need answers.&lt;/P&gt;
&lt;P&gt;First, I see Quarter and Weekending but with only 3 weekending values in a quarter. Will you have more weeks in your actual data? Will perhaps the 'last' quarter have a different number of weeks than other quarters? (This answer goes to one of the ways that Proc Report sums columns)&lt;/P&gt;
&lt;P&gt;Is there a particular reason that Weekending is just a number and not set up as actual SAS date values?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One approach, that simplifies the "column total" is custom multilabel format:&lt;/P&gt;
&lt;PRE&gt;proc format library=work;
value weekendingtr (multilabel)
20240101-20240330 = 'Subtotal'
20240101-20240330 = [f8.]
20240401-20240630 = 'Subtotal'
20240401-20240630 = [f8.]
;
run;

proc report data = one nowd;
column client_rank client client_id quarter, weekending, sales ("Total" sales=tot);
define client_rank / noprint group;
define client / "Client" group;
define client_id / "Client ID" group;
define quarter / " " across;
define weekending / " " across nozero&lt;FONT size="5" color="#0000FF"&gt;&lt;STRONG&gt; format=weekendingtr. mlf&lt;/STRONG&gt;&lt;/FONT&gt;;
define sales / "Sales" analysis sum format=comma12.0;
define tot / "Sales" analysis sum format=comma12.0;

rbreak after / summarize;
compute after;
client = "Total";
endcomp;
define client_rank / order group;
run;&lt;/PRE&gt;
&lt;P&gt;Such a format needs a little bit of explaining as most procedures will not use the multiple label approach. You define range of values that provide different display values. In this case the "quarter" as a whole gets "Subtotal" and the individual Weekending values get something that displays the individual value.&lt;/P&gt;
&lt;P&gt;Note that the way I have done this provides for additional Weekending values in the quarters and will adjust if there are more "weekending" values for some quarter than for others.&lt;/P&gt;
&lt;P&gt;If this were my project I would make the Weekendingqtr format include a longer range of values so I don't forget to change it when the Qtr3 data shows up.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Only Procs Report, Tabulate, Means and Summary&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The real change I would make would be to have the Weekending values actual SAS date values because it would be possible to get a variety of different reports just by changing the format a bit easier as SAS has formats to do year, quarter, month, week (with some caveats).&lt;/P&gt;</description>
      <pubDate>Fri, 10 May 2024 19:50:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Proc-Report-Subtotal-Columns/m-p/927944#M44756</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-05-10T19:50:20Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Report - Subtotal Columns</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Proc-Report-Subtotal-Columns/m-p/927980#M44757</link>
      <description>&lt;P&gt;I think to render this kind of pivot table ,the bese choice is using PROC TABULATE.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; 

data one;
input client_rank client $9. client_id quarter $ weekending sales;
datalines;
1 Apple 12345 Q1 20240106 1000
1 Apple 12345 Q1 20240113 2000
1 Apple 12345 Q1 20240127 5000
1 Apple 12345 Q2 20240413 3000
1 Apple 12345 Q2 20240420 4000
1 Apple 12345 Q2 20240427 2000
2 Microsoft 67890 Q1 20240106 3000
2 Microsoft 67890 Q1 20240113 1000
2 Microsoft 67890 Q1 20240127 2500
2 Microsoft 67890 Q2 20240413 4000
2 Microsoft 67890 Q2 20240420 500
2 Microsoft 67890 Q2 20240427 1500
;
run;
proc tabulate data=one format=comma32.;
class client client_id quarter weekending;
var sales;
table client*client_id all, quarter=''*(weekending='' all='SubTotal')*sales*sum='' all*sales*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-1715411513691.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/96447i482111CB902C7F1C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1715411513691.png" alt="Ksharp_0-1715411513691.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 11 May 2024 07:12:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Proc-Report-Subtotal-Columns/m-p/927980#M44757</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-05-11T07:12:01Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Report - Subtotal Columns</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Proc-Report-Subtotal-Columns/m-p/928012#M44758</link>
      <description>&lt;P&gt;Hi:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; You can also do a Subtotal column with PROC REPORT very similar to how you generated the last column for Total. You just needed to get the nesting correct (which is why I color coded the parentheses.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Cynthia_sas_0-1715473484120.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/96450i4BB41A82E4934FDE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Cynthia_sas_0-1715473484120.png" alt="Cynthia_sas_0-1715473484120.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; (I deleted your extra define statement for client_rank because it was not necessary.)&lt;/P&gt;
&lt;P&gt;Cynthia&lt;/P&gt;</description>
      <pubDate>Sun, 12 May 2024 00:26:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Proc-Report-Subtotal-Columns/m-p/928012#M44758</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2024-05-12T00:26:41Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Report - Subtotal Columns</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Proc-Report-Subtotal-Columns/m-p/928213#M44783</link>
      <description>&lt;P&gt;Greatly appreciate everyone's thoughtful response!&amp;nbsp; Cynthia's response was most precisely what I was going for (I need to brush up on my nesting), but I really like the additional thoughts on using Proc Format to show the date range in my subtotals, as well as considering Proc Tabulate next time for nested totaling/subtotaling.&amp;nbsp; Depending on client requirements, I may circle back to some of those ideas.&amp;nbsp; Thanks everyone!&lt;/P&gt;</description>
      <pubDate>Mon, 13 May 2024 22:03:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Proc-Report-Subtotal-Columns/m-p/928213#M44783</guid>
      <dc:creator>cbal324</dc:creator>
      <dc:date>2024-05-13T22:03:06Z</dc:date>
    </item>
  </channel>
</rss>

