You can create multiple summary rows with PROC REPORT when more than one GROUP/ORDER variable is requested by adding dummy grouping variables and using a BREAK statement. The following steps are necessary for creating the desired summary rows:
See the sample code on the Full Code tab for an illustration.
For an example using only one GROUP/ORDER variable, see Usage Note 24536: How do I create multiple summary rows without using a LINE statement?
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
A summary row is created for each value of the Type variable, the second GROUP variable displayed in the report.
This logic is applicable in all SAS releases. The Sashelp.Cars data set is available beginning in SAS® 9.2.
data cars1;
set sashelp.cars;
dummy1 = 1;
dummy2 = 1;
dummy3 = 1;
dummy4 = 1;
dummy5 = 1;
dummy6 = 1;
run;
proc report data=cars1 nowd;
column dummy1 dummy2 dummy3 dummy4 dummy5 dummy6
origin type msrp invoice;
define dummy1 / group noprint;
define dummy2 / group noprint;
define dummy3 / group noprint;
define dummy4 / group noprint;
define dummy5 / group noprint;
define dummy6 / group noprint;
define origin / group;
define type / group;
define msrp / format=dollar12.;
define invoice / format=dollar12.;
break after dummy1 / summarize;
break after dummy2 / summarize;
break after dummy3 / summarize;
break after dummy4 / summarize;
break after dummy5 / summarize;
break after dummy6 / summarize;
/* Calculate subtotals */
compute invoice; *Use the last variable on the COLUMN statement;
if upcase(type) = "HYBRID" then do;
msrptyp6 + msrp.sum;
invotyp6 + invoice.sum;
end;
else if upcase(type) = "SUV" then do;
msrptyp5 + msrp.sum;
invotyp5 + invoice.sum;
end;
else if upcase(type) = "SEDAN" then do;
msrptyp4 + msrp.sum;
invotyp4 + invoice.sum;
end;
else if upcase(type) = "SPORTS" then do;
msrptyp3 + msrp.sum;
invotyp3 + invoice.sum;
end;
else if upcase(type) = "TRUCK" then do;
msrptyp2 + msrp.sum;
invotyp2 + invoice.sum;
end;
else if upcase(type) = "WAGON" then do;
msrptyp1 + msrp.sum;
invotyp1 + invoice.sum;
end;
endcomp;
/* Reassign to subtotal values */
compute after dummy6;
origin = "TOTALS";
type = "Hybrid";
msrp.sum = msrptyp6;
invoice.sum = invotyp6;
endcomp;
compute after dummy5;
type = "SUV";
msrp.sum = msrptyp5;
invoice.sum = invotyp5;
endcomp;
compute after dummy4;
type = "Sedan";
msrp.sum = msrptyp4;
invoice.sum = invotyp4;
endcomp;
compute after dummy3;
type = "Sports";
msrp.sum = msrptyp3;
invoice.sum = invotyp3;
endcomp;
compute after dummy2;
type = "Truck";
msrp.sum = msrptyp2;
invoice.sum = invotyp2;
endcomp;
compute after dummy1;
type = "Wagon";
msrp.sum = msrptyp1;
invoice.sum = invotyp1;
endcomp;
run;
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
Multiple Rows Summarizing Type Variable
Origin Type MSRP Invoice Asia Hybrid $59,760 $55,288 SUV $739,225 $672,912 Sedan $2,139,813 $1,954,101 Sports $552,681 $503,556 Truck $163,069 $150,412 Wagon $254,581 $234,875 Europe SUV $483,460 $442,913 Sedan $3,353,380 $3,096,312 Sports $1,655,970 $1,501,327 Wagon $454,215 $420,043 USA SUV $864,730 $781,696 Sedan $2,307,495 $2,125,714 Sports $407,315 $370,302 Truck $435,524 $392,390 Wagon $156,420 $144,451 TOTALS Hybrid $59,760 $55,288 SUV $2,087,415 $1,897,521 Sedan $7,800,688 $7,176,127 Sports $2,615,966 $2,375,185 Truck $598,593 $542,802 Wagon $865,216 $799,369
Type: | Sample |
Date Modified: | 2011-10-18 14:23:45 |
Date Created: | 2011-08-11 15:37:14 |
Product Family | Product | Host | SAS Release | |
Starting | Ending | |||
SAS System | Base SAS | OS/2 | ||
Microsoft Windows NT Workstation | ||||
Microsoft Windows 2000 Professional | ||||
Microsoft® Windows® for x64 | ||||
Microsoft Windows XP 64-bit Edition | ||||
Microsoft Windows 2000 Server | ||||
Microsoft Windows Server 2003 Enterprise 64-bit Edition | ||||
Microsoft Windows 2000 Datacenter Server | ||||
Microsoft Windows Server 2003 Datacenter 64-bit Edition | ||||
Microsoft Windows 2000 Advanced Server | ||||
Microsoft Windows 95/98 | ||||
Microsoft® Windows® for 64-Bit Itanium-based Systems | ||||
z/OS | ||||
Z64 | ||||
OpenVMS VAX | ||||
Microsoft Windows Server 2003 Datacenter Edition | ||||
Microsoft Windows Server 2003 Enterprise Edition | ||||
Microsoft Windows Server 2003 Standard Edition | ||||
Microsoft Windows Server 2003 for x64 | ||||
Microsoft Windows Server 2008 | ||||
Microsoft Windows Server 2008 for x64 | ||||
Microsoft Windows XP Professional | ||||
Windows 7 Enterprise 32 bit | ||||
Windows 7 Enterprise x64 | ||||
Windows 7 Home Premium 32 bit | ||||
Windows 7 Home Premium x64 | ||||
Windows 7 Professional 32 bit | ||||
Windows 7 Professional x64 | ||||
Windows 7 Ultimate 32 bit | ||||
Windows 7 Ultimate x64 | ||||
Windows Millennium Edition (Me) | ||||
Windows Vista | ||||
Windows Vista for x64 | ||||
64-bit Enabled AIX | ||||
64-bit Enabled HP-UX | ||||
64-bit Enabled Solaris | ||||
ABI+ for Intel Architecture | ||||
AIX | ||||
HP-UX | ||||
HP-UX IPF | ||||
IRIX | ||||
Linux | ||||
Linux for x64 | ||||
Linux on Itanium | ||||
OpenVMS Alpha | ||||
OpenVMS on HP Integrity | ||||
Solaris | ||||
Solaris for x64 | ||||
Tru64 UNIX |