<?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: Formatting grand totals in datasets in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Formatting-grand-totals-in-datasets/m-p/423661#M104219</link>
    <description>&lt;P&gt;Hi:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; You'll need to make REGION a length of 11 to fit the "Grand Total" in the column, but assuming you do that, then this PROC REPORT code does what you want:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc report data=sales;
  column region repid amount;
  define region / group;
  define repid / group;
  define amount / sum;
  rbreak after / summarize;
  compute after;
    region = 'Grand Total';
  endcomp;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The repetitious display of REGION is a side effect of GROUP usage (there is a way to work around that), but another nice side effect is that REPID is automatically blanked out on the summary line.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;cynthia&lt;/P&gt;</description>
    <pubDate>Tue, 26 Dec 2017 23:49:44 GMT</pubDate>
    <dc:creator>Cynthia_sas</dc:creator>
    <dc:date>2017-12-26T23:49:44Z</dc:date>
    <item>
      <title>Formatting grand totals in datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formatting-grand-totals-in-datasets/m-p/423593#M104185</link>
      <description>&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; sales; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; @&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt; region &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;$char8.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; @&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;10&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt; repid &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;4.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt; @&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;15&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt; amount &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;10.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt; ; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;format&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; amount &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;dollar12.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;datalines&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;NORTH 1001 1000000&lt;/P&gt;
&lt;P&gt;NORTH 1002 1100000&lt;/P&gt;
&lt;P&gt;NORTH 1003 1550000&lt;/P&gt;
&lt;P&gt;NORTH 1008 1250000&lt;/P&gt;
&lt;P&gt;NORTH 1005 900000&lt;/P&gt;
&lt;P&gt;SOUTH 1007 2105000&lt;/P&gt;
&lt;P&gt;SOUTH 1010 875000&lt;/P&gt;
&lt;P&gt;SOUTH 1012 1655000&lt;/P&gt;
&lt;P&gt;EAST 1051 2508000&lt;/P&gt;
&lt;P&gt;EAST 1055 1805000&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;sort&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;data&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=sales; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;by&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; region; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;means&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;noprint&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;data&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;= sales;&lt;/FONT&gt;&lt;FONT color="#008000" face="Courier New" size="3"&gt;/*This provides a grand total only*/&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;output&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;out&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;= sales_tot &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;sum&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;= ;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; sales_tot_1;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; sales sales_tot; /*I am including the details and sum at bottom by combining both datasets*/&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;This gives me the following&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;REGION REPID&amp;nbsp;&amp;nbsp;&amp;nbsp; AMOUNT&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _TYPE_&amp;nbsp; _FREQ_&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;EAST&amp;nbsp;&amp;nbsp; 1051&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $2,508,000&amp;nbsp;&amp;nbsp;&lt;BR /&gt;EAST&amp;nbsp;&amp;nbsp; 1055&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $1,805,000&amp;nbsp;&amp;nbsp;&lt;BR /&gt;NORTH&amp;nbsp;&amp;nbsp;1055&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;$1,000,000&amp;nbsp;&amp;nbsp;&lt;BR /&gt;NORTH&amp;nbsp; 1002&amp;nbsp;&amp;nbsp;&amp;nbsp; $1,100,000&amp;nbsp;&amp;nbsp;&lt;BR /&gt;NORTH&amp;nbsp; 1003&amp;nbsp;&amp;nbsp;&amp;nbsp; $1,550,000&amp;nbsp;&amp;nbsp;&lt;BR /&gt;NORTH&amp;nbsp; 1008&amp;nbsp;&amp;nbsp;&amp;nbsp; $1,250,000&amp;nbsp;&amp;nbsp;&lt;BR /&gt;NORTH&amp;nbsp; 1005&amp;nbsp;&amp;nbsp;&amp;nbsp; $900,000&amp;nbsp;&amp;nbsp;&lt;BR /&gt;SOUTH&amp;nbsp; 1007&amp;nbsp;&amp;nbsp;&amp;nbsp; $2,105,000&amp;nbsp;&amp;nbsp;&lt;BR /&gt;SOUTH&amp;nbsp; 1010&amp;nbsp;&amp;nbsp;&amp;nbsp; $875,000&amp;nbsp;&amp;nbsp;&lt;BR /&gt;SOUTH&amp;nbsp; 1012&amp;nbsp;&amp;nbsp;&amp;nbsp; $1,655,000&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 10154&amp;nbsp;&amp;nbsp;&amp;nbsp;$14,748,000&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 10&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;How can I format this so I can&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;1. Display the text 'Grand Total' under the column REGION&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;2. Assign a blank under REPID&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;3. Remove _TYPE_ and _FREQ_&lt;/FONT&gt;&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;/P&gt;</description>
      <pubDate>Tue, 26 Dec 2017 15:02:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formatting-grand-totals-in-datasets/m-p/423593#M104185</guid>
      <dc:creator>Q1983</dc:creator>
      <dc:date>2017-12-26T15:02:52Z</dc:date>
    </item>
    <item>
      <title>Re: Formatting grand totals in datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formatting-grand-totals-in-datasets/m-p/423594#M104186</link>
      <description>&lt;P&gt;A couple of small changes to your code will accomplish what you want:&lt;/P&gt;
&lt;PRE&gt;data sales;
  informat region $8.;
  input region repid amount;
  format amount dollar12.;
  datalines;
NORTH 1001 1000000
NORTH 1002 1100000
NORTH 1003 1550000
NORTH 1008 1250000
NORTH 1005 900000
SOUTH 1007 2105000
SOUTH 1010 875000
SOUTH 1012 1655000
EAST 1051 2508000
EAST 1055 1805000
;

proc sort data=sales;
  by region;
run;

proc means noprint data= sales nway;/*This provides a grand total only*/
  var amount;
  output out= sales_tot (drop=_:) sum= ;
run;

data sales_tot_1;
  length region $11;
  set sales sales_tot (in=tot);
  if tot then region='Grand Total';
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Dec 2017 15:24:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formatting-grand-totals-in-datasets/m-p/423594#M104186</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-12-26T15:24:01Z</dc:date>
    </item>
    <item>
      <title>Re: Formatting grand totals in datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formatting-grand-totals-in-datasets/m-p/423596#M104187</link>
      <description>&lt;P&gt;You probably want to produce a REPORT and not a DATASET, but let's see what we can do.&lt;/P&gt;
&lt;P&gt;First tell proc means/summary which variables you want to sum and to drop the automatic variables.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=sales nway ;
  var amount ;
  output out= sales_tot (drop=_type_ _freq_) sum= ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then when you combine the datasets figure out what records are coming from the summary dataset and adjust REGION.&amp;nbsp; You will probably need to make sure REGION is long enough to store 'GRAND TOTAL'.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data sales_tot_1 ;
  length region $%length(GRAND TOTAL);
  set sales sales_tot (in=in2);
  if in2 the region='GRAND TOTAL';
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Dec 2017 15:25:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formatting-grand-totals-in-datasets/m-p/423596#M104187</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-12-26T15:25:26Z</dc:date>
    </item>
    <item>
      <title>Re: Formatting grand totals in datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formatting-grand-totals-in-datasets/m-p/423597#M104188</link>
      <description>Hi:&lt;BR /&gt;  This sounds to me like a REPORT and not a data set. You could do this with either TABULATE or REPORT. What will you do with your data set when you have it?&lt;BR /&gt;cynthia</description>
      <pubDate>Tue, 26 Dec 2017 15:26:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formatting-grand-totals-in-datasets/m-p/423597#M104188</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2017-12-26T15:26:11Z</dc:date>
    </item>
    <item>
      <title>Re: Formatting grand totals in datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formatting-grand-totals-in-datasets/m-p/423603#M104190</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another way using proc sql&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table sales_tot_1 as&lt;BR /&gt;select * from sales&lt;BR /&gt;union all&lt;BR /&gt;select "Grand_Total", . , sum(amount) as amount from sales;&lt;BR /&gt;quit;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Dec 2017 16:31:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formatting-grand-totals-in-datasets/m-p/423603#M104190</guid>
      <dc:creator>stat_sas</dc:creator>
      <dc:date>2017-12-26T16:31:30Z</dc:date>
    </item>
    <item>
      <title>Re: Formatting grand totals in datasets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formatting-grand-totals-in-datasets/m-p/423661#M104219</link>
      <description>&lt;P&gt;Hi:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; You'll need to make REGION a length of 11 to fit the "Grand Total" in the column, but assuming you do that, then this PROC REPORT code does what you want:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc report data=sales;
  column region repid amount;
  define region / group;
  define repid / group;
  define amount / sum;
  rbreak after / summarize;
  compute after;
    region = 'Grand Total';
  endcomp;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The repetitious display of REGION is a side effect of GROUP usage (there is a way to work around that), but another nice side effect is that REPID is automatically blanked out on the summary line.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;cynthia&lt;/P&gt;</description>
      <pubDate>Tue, 26 Dec 2017 23:49:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formatting-grand-totals-in-datasets/m-p/423661#M104219</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2017-12-26T23:49:44Z</dc:date>
    </item>
  </channel>
</rss>

