In some situations, lines are needed between groups in a report, meaning that the data itself needs to be sectioned. Neither the TEMPLATE procedure nor general border settings can create lines between groups. To insert border lines between groups with PROC REPORT, an extra group variable needs to be created and border control attributes need to be used in CALL DEFINE statements.
The sample code on the Full Code tab contains three group variables: Make, Cylinders, and Enginesize. A line is drawn after the last row of each Cylinders value.
It is much easier to figure out the first row in a group with PROC REPORT than it is to figure out the last row in the group. However, RTF and PDF control where a page break occurs. If the first row is used and the top of a Cylinder section occurs at the top of a page, then the line under the header is removed. Therefore, the code needs to put a line at the bottom of a Cylinder section instead of at the top. The key to this method is determining the last Enginesize value within a Cylinder value. Pre-processing is required, including two PROC SORT steps and two DATA steps.
The data has to be pre-processed to create the new group variable, which is an indicator for the last Enginesize within Cylinders. The indicator variable is then placed in the COLUMN statement and defined as a GROUP (or ORDER) variable.
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.
/* Create a data set of unique Make, Cylinders, and Enginesize values */
proc sort data=sashelp.cars(keep=make cylinders enginesize) out=unique nodupkey;
by make cylinders enginesize;
run;
/* Determine what the last Enginesize value is within each Cylinders value */
data unique2;
set unique;
by make cylinders enginesize;
if last.cylinders;
rename enginesize=last_group_ind;
run;
/* Merge back into the full data set */
proc sort data=sashelp.cars out=cars;
by make cylinders;
run;
data cars;
merge cars unique2;
by make cylinders;
run;
proc report data=cars nowd style(report)=[frame=void rules=group] style(header)=[background=white];
column make cylinders last_group_ind enginesize mpg_city mpg_highway;
define make / group;
define cylinders / group order=internal;
define enginesize / group order=internal;
define last_group_ind / group noprint;
/* Create a variable that will hold Last_group_ind on every row */
compute last_group_ind;
if last_group_ind ^= . then hold=last_group_ind;
endcomp;
/* Insert the bottom border for the last group within the grouping */
compute enginesize;
if hold = enginesize then do;
call define(_row_,'style','style=[borderbottomwidth=1pt borderbottomcolor=black]');
call define('make','style','style=[borderbottomcolor=white]');
end;
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.
Type: | Sample |
Date Modified: | 2013-07-09 14:32:25 |
Date Created: | 2013-06-18 16:42:30 |
Product Family | Product | Host | SAS Release | |
Starting | Ending | |||
SAS System | Base SAS | Solaris for x64 | 9.2 TS1M0 | |
OpenVMS on HP Integrity | 9.2 TS1M0 | |||
Linux for x64 | 9.2 TS1M0 | |||
Linux | 9.2 TS1M0 | |||
HP-UX IPF | 9.2 TS1M0 | |||
64-bit Enabled Solaris | 9.2 TS1M0 | |||
64-bit Enabled HP-UX | 9.2 TS1M0 | |||
64-bit Enabled AIX | 9.2 TS1M0 | |||
Windows Vista for x64 | 9.2 TS1M0 | |||
Windows Vista | 9.2 TS1M0 | |||
Microsoft Windows XP Professional | 9.2 TS1M0 | |||
Microsoft Windows Server 2003 Standard Edition | 9.2 TS1M0 | |||
Microsoft Windows Server 2003 Enterprise Edition | 9.2 TS1M0 | |||
Microsoft Windows Server 2003 Datacenter Edition | 9.2 TS1M0 | |||
Microsoft® Windows® for x64 | 9.2 TS1M0 | |||
Microsoft Windows XP 64-bit Edition | 9.2 TS1M0 | |||
Microsoft Windows Server 2003 Enterprise 64-bit Edition | 9.2 TS1M0 | |||
Microsoft Windows Server 2003 Datacenter 64-bit Edition | 9.2 TS1M0 | |||
Microsoft® Windows® for 64-Bit Itanium-based Systems | 9.2 TS1M0 | |||
z/OS | 9.2 TS1M0 |