TEMPLATE Procedure: Creating Table Templates

Example 6: Creating Master Templates

Features:
DEFINE TABLE statement :
CELLSTYLE AS statement: STYLE_ variable
CELLSTYLE AS statement: _ROW_ variable
DEFINE COLUMN statement :
CELLSTYLE AS statement:_VAL_ variable
STYLE= column attribute statement

DEFINE HEADER statement : STYLE= column attribute statement

LINK statement

Details

The following program creates four master templates for tables: Base.Template.Table, Base.Template.Column, Base.Template.Header, and Base.Template.Footer. These templates contain style information that creates alternating blue and green row colors and specific styles for headers and footers. Once they are created, master templates are applied to every table created by SAS until you specifically remove the master template or it is overridden by another table template created by PROC TEMPLATE.

Program

title;
options nodate nostimer LS=78 PS=60;
proc template;
define table base.template.table;
   cellstyle mod(_row_, 2) and _style_ ^= "RowHeader" as {background=blue
color=white},
             mod(_row_, 2) and _style_ = "RowHeader" as {background=green
color=white};
end;
define column base.template.column;
   style={fontstyle=italic};
   cellstyle _val_ > 5 as {fontsize=15pt},
             _val_ = "Num" as {fontsize=20pt};
end;
define header base.template.header;
   style={fontsize=20pt color=purple};
end;
link base.template.footer to base.template.header;
run;
ods select variables;
proc contents data=sashelp.class; 
run;
proc template;
delete base.template.table;
delete base.template.column;
delete base.template.header;
delete base.template.footer;

run;

Program Description

Set the SAS system options.
title;
options nodate nostimer LS=78 PS=60;
Create the master parent Base.Template.Table and specify which style element and style attributes to use for different cells in a row. The DEFINE TABLE statement creates the master parent Base.Template.Table. This template will be applied to every table created by SAS, unless it is overridden by another template created by PROC TEMPLATE, removed with the DELETE statement, or manually removed from the item store. The CELLSTYLE-AS statement specifies the style element and style attributes to use for cells in each of the rows in a table, which creates the alternating row colors in the output. If the row is even numbered and does not contain a style element named RowHeader, then the cell has a green background color and white font color. Similarly, if the row is even numbered and does contain a style element named RowHeader, then the cell has a blue background color and white font color.
proc template;
define table base.template.table;
   cellstyle mod(_row_, 2) and _style_ ^= "RowHeader" as {background=blue
color=white},
             mod(_row_, 2) and _style_ = "RowHeader" as {background=green
color=white};
end;
Create the master parent Base.Template.Column and specify which style element and style attributes to use for different cells in a column. The DEFINE TABLE statement creates the master parent Base.Template.Column. This template will be applied to every table created by SAS, unless it is overridden by another template created by PROC TEMPLATE, removed with the DELETE statement, or manually removed from the item store. The STYLE= column attribute statement specifies that column fonts are italicized. The first CELLSTYLE-AS statement specifies that if the value of the cell is greater than five, then the font size is 15pt; and if the value of the cell is equal to "Num", then the font size is 20pt.
define column base.template.column;
   style={fontstyle=italic};
   cellstyle _val_ > 5 as {fontsize=15pt},
             _val_ = "Num" as {fontsize=20pt};
end;
Create the master parent Base.Template.Header and specify the font size and font color for the headers and footers. The DEFINE TABLE statement creates the master parent Base.Template.Header. The STYLE= header attribute statement specifies that the header font is 20pt and purple. The LINK statement creates the Base.Template.Footer master template and links it to the Base.Template.Header template, which it inherits its characteristics from. Base.Template.Header and Base.Template.Footer will be applied to every table created by SAS, unless they are overridden by another template created by PROC TEMPLATE, removed with the DELETE statement, or manually removed from the item store.
define header base.template.header;
   style={fontsize=20pt color=purple};
end;
link base.template.footer to base.template.header;
run;
View the contents of the SAS data set.The CONTENTS procedure shows the contents of the SAS data set SasHelp.Class.
ods select variables;
proc contents data=sashelp.class; 
run;
Delete the master templates. The DELETE statement deletes each master template. If you do not delete them, they will be applied to all of your tabular output until you do delete them.
proc template;
delete base.template.table;
delete base.template.column;
delete base.template.header;
delete base.template.footer;

run;

Output

Using Master Templates for HTML Output
Using Master Templates For HTML Output