TEMPLATE Procedure: Creating Table Templates

Example 7: Table Header and Footer Border Formatting

Features:
Border control style attributes:
BORDERBOTTOMCOLOR=
BORDERBOTTOMSTYLE=
BORDERBOTTOMWIDTH=
BORDERTOPCOLOR=
BORDERTOPSTYLE=
BORDERTOPWIDTH=

DEFINE statement

DEFINE STYLE statement

EDIT statement

FOOTER statement

HEADER statement

PARENT= statement

PREFORMATTED= header attribute

STYLE statement

WIDTH= header attribute

Other features:
Other ODS features:
ODS RTF
ODS SELECT
Data set: Stats and Stats2

Details

You can use the TableHeaderContainer and TableFooterContainer style elements along with the border control style attributes to change the borders of the regions surrounding the table header and footer.
Note: The TableHeaderContainer and TableFooterContainer style elements are valid only in the RTF destination.

Program

options nodate nonumber;

title  "TableHeaderContainer, TableFooterContainer, and Border Control Style
     Attributes";
title2 "Allows Control of Borders Between the Header, Body, and Footer of a
     Table";
ods html close;
proc template;
   define style  HeadersFootersBorders;
   parent=styles.rtf;       
   style TableHeaderContainer from TableHeaderContainer /
      borderbottomwidth=12
      borderbottomcolor=blue
      borderbottomstyle=dotted; 
   style TableFooterContainer from TableFooterContainer /
      bordertopwidth=6
      bordertopcolor=red
      bordertopstyle=double;
   style table from table /
      cellspacing=0 rules=groups frame=void;
   end;
run;
proc template;
   edit Base.Datasets.Members;
      header hd1;
      footer ft1;
      define hd1;
         preformatted=on;
         just=l;
         text"     Table Header with Leading and Trailing Blanks    ";
      end;
      define ft1;
         preformatted=on;
         just=l;
         text"     Table Footer with Leading and Trailing Blanks    ";
      end;
      edit name;
       define header myheader;
         just=l;
         preformatted=on;
         text "     My new header";
       end;
       header=myheader;
       width=memname_width width_max=memname_width_max;
       preformatted=on;
      end;
   end;
run;
ods rtf file="headerfooters.rtf" style=HeadersFootersBorders;
ods select members;
proc datasets lib=work;
run;
quit;
ods rtf close;

Program Description

Set the SAS system options and specify titles. The OPTIONS statement sets the SAS system options and the TITLE statements specify titles for the output.
options nodate nonumber;

title  "TableHeaderContainer, TableFooterContainer, and Border Control Style
     Attributes";
title2 "Allows Control of Borders Between the Header, Body, and Footer of a
     Table";
Close the HTML destination. The ODS HTML CLOSE statement closes the HTML destination to conserve system resources.
ods html close;
Create the new style HeadersFootersBorders. The PROC TEMPLATE statement starts the TEMPLATE procedure. The DEFINE STYLE statement creates a new style HeadersFootersBorders. The PARENT= statement specifies that the new style inherits all of its style elements and style attributes from the Styles.RTF style.
proc template;
   define style  HeadersFootersBorders;
   parent=styles.rtf;       
Modify the TableHeaderContainer style element. The STYLE statement with the FROM option specified creates the style element TableHeaderContainer, which inherits all of its style elements and style attributes from the instance of TableHeaderContainer in the Styles.RTF style. The BORDERBOTTOMWIDTH=, BORDERBOTTOMCOLOR=, and BORDERBOTTOMSTYLE= style attributes specify the width, color, and line style of the bottom border of the table header.
   style TableHeaderContainer from TableHeaderContainer /
      borderbottomwidth=12
      borderbottomcolor=blue
      borderbottomstyle=dotted; 
Modify the TableFooterContainer style element. The STYLE statement with the FROM option specified creates the style element TableFooterContainer, which inherits all of its style elements and style attributes from the instance of TableFooterContainer in the Styles.RTF style. The BORDERTOPWIDTH=, BORDERTOPCOLOR=, and BORDERTOPSTYLE= style attributes specify the width, color, and line style of the top border of the table footer.
   style TableFooterContainer from TableFooterContainer /
      bordertopwidth=6
      bordertopcolor=red
      bordertopstyle=double;
Modify the Table style element. The STYLE statement with the FROM option specified creates the style element Table, which inherits all of its style elements and style attributes from the instance of Table in the Styles.RTF style. The CELLSPACING=, RULES=, and FRAME= attributes modify the cellspacing, rules, and frame of the table.
   style table from table /
      cellspacing=0 rules=groups frame=void;
   end;
run;
Edit the Base.Datasets.Members table template. The EDIT statement, along with the table template DEFINE statements and attributes, modifies the Base.Datasets.Members table template.
proc template;
   edit Base.Datasets.Members;
      header hd1;
      footer ft1;
      define hd1;
         preformatted=on;
         just=l;
         text"     Table Header with Leading and Trailing Blanks    ";
      end;
      define ft1;
         preformatted=on;
         just=l;
         text"     Table Footer with Leading and Trailing Blanks    ";
      end;
      edit name;
       define header myheader;
         just=l;
         preformatted=on;
         text "     My new header";
       end;
       header=myheader;
       width=memname_width width_max=memname_width_max;
       preformatted=on;
      end;
   end;
run;
Create the RTF file, select the output object and run PROC DATASETS. The ODS RTF statement specifies the file that will contain the RTF output. The STYLE= option specifies the style to apply to the output. The ODS SELECT statement selects the output object Members to be sent to the open destinations.
ods rtf file="headerfooters.rtf" style=HeadersFootersBorders;
ods select members;
proc datasets lib=work;
run;
quit;
Close the open destinations and open the LISTING destination. The ODS _ALL_ CLOSE statement closes all open destinations and the files that are associated with them. If you do not close the destinations, then you will not be able to view the files. The ODS LISTING statement opens the LISTING destination.
ods rtf close;

RTF Output

RTF Output with Custom Headers and Footers
RTF Output with Custom Headers and Footers