3. 3
proc template;
source styles.HTMLBlue;
run;
Would print the following statements to the
log. It is recommended to check the source
code of a template before beginning to alter it,
to help decide what needs to be changed.
define style Styles.HTMLBlue;
parent = styles.statistical;
style GraphColors from GraphColors /
'gconramp3cend' = cx31702F
'gconramp3cneutral' = cx2F6A9C
'gconramp3cstart' = cxA23A2E
'gramp3cend' = cxD05B5B
'gramp3cneutral' = cxFAFBFE
'gramp3cstart' = cx667FA2
'gcontrollim' = cxE6F2FF
'gccontrollim' = cxBFC7D9
'gruntest' = cxCAE3FF
'gcruntest' = cxBF4D4D
'gclipping' = cxFFFFC6
'gcclipping' = cxC1C100
'gaxis' = cx989EA1
'greferencelines' = cx989EA1;
style colors from colors /
'link2' = cx0000FF
'link1' = cx800080
'docbg' = cxFAFBFE
'contentbg' = cxFAFBFE
'systitlebg' = cxFAFBFE
'titlebg' = cxFAFBFE
'proctitlebg' = cxFAFBFE
'headerbg' = cxEDF2F9
'captionbg' = cxFAFBFE
'captionfg' = cx112277
'bylinebg' = cxFAFBFE
'notebg' = cxFAFBFE
'tablebg' = cxFAFBFE
'batchbg' = cxFAFBFE
'systitlefg' = cx112277
'titlefg' = cx112277
'proctitlefg' = cx112277
'bylinefg' = cx112277
'notefg' = cx112277;
style Header from Header /
bordercolor = cxB0B7BB
backgroundcolor = cxEDF2F9
color = cx112277;
style Table from Table /
cellpadding = 5;
style Graph from Graph /
attrpriority = "Color";
style GraphFit2 from GraphFit2 /
linestyle = 1;
style GraphClipping from GraphClipping /
markersymbol = "circlefilled";
end;
NOTE: Path 'Styles.HTMLBlue' is in:
SASHELP.TMPLMST.r
5. How are SAS Templates created?
5.1. Style Templates
The first step to creating a template is
defining the type. To create a new style
template, we use the DEFINE statement
within a PROC TEMPLATE, and give the new
template a name. The DEFINE statement
must be paired with an END statement, to let
SAS know that you have finished editing your
template.
proc template;
define style
Styles.NewTemplate;
end;
run;
Of course, this code does not create a usable
template. Checking the log shows the
following note.
NOTE: STYLE 'Styles.NewTemplate' has been
saved to: SASUSER.TEMPLAT
From here, we may either create a template
from scratch, or by altering an existing
template.
Creating a Style Template from Default
This is the most basic method of creating a
template. Similar to the SET statement within
a DATA step, the PARENT statement within a
PROC TEMPLATE will provide a base to begin
with, which can be slightly adjusted to fit your
needs.
The first step is finding a good parent
template to use. In this case the example will
use STYLE.OCEAN in the SASHELP.TMPLMST
store. We can call this template when we go
SUGI Beginning Tutorials
SUGI Beginning Tutorials
4. 4
to print data to a file with a simple ODS
statement.
ods destination file =
'filename.destination'
style = ocean;
proc print data = example;
title 'Colorful Output';
run;
ods destination close;
More information on how to apply templates
is discussed in section 6.
The STYLE option in this ODS statement will
produce the following output style. Here, this
code has been run with a dataset named
EXAMPLE, containing three variables; x
(character), y (numeric), and z (numeric). It
was produced only to show the options of
PROC TEMPLATE and its effects on character
and numeric data.
Colorful Output
Obs X y Z
1 One 2 3
2 Fou
r
5 6
With only one statement, the output of
normal blue has become a vibrant ocean of
color. Changing this output from these colors
and selections is only a few option statements
away from looking completely different.
The code below shows how to create a new
style template named FANCY, based off of the
default OCEAN template. The code is split into
sections to analyze each major statement.
proc template;
define style styles.Fancy;
parent = styles.Ocean;
class body /
backgroundcolor = black
color = green
fontfamily = "Times New Roman"
;
This first part points out a few important key
concepts about PROC TEMPLATE. The
DEFINE statement works as it normally
would in defining a DATA set. This one is
called STYLES.FANCY and would be found in
SASUSER.TEMPLAT. The parent statement is
similar to the STYLE statement used in the
ODS code used earlier, in the fact that if an
option is not specified, SAS will fill in the
options with the default options from that of
STYLES.OCEAN. The CLASS statement defines
the section of the output to change. The
BACKGROUNDCOLOR option changes the
main bar which is usually white to black, and
likewise the COLOR option changes the font
color from black to green. Finally, the
FONTFAMILY option changes the title bar to a
preferred font.
class systemtitle /
fontfamily = "Courier New"
color = green
fontsize = 16pt
fontweight = bold
;
The CLASS SYSTEMTITLE statement will aid
in changing the font and color of the title text.
Some of the options in this statement are
FONTSIZE which changes the size of the title,
and FONTWEIGHT which changes the
boldness of the text.
class data /
fontfamily = "Times New Roman"
backgroundcolor = black
color = red;
end;
CLASS DATA changed the appearance of the
data points. There are many different CLASS
statements that can help you change many
other characteristics of your output.
This is what the same data set looks like with
the new template:
SUGI Beginning Tutorials
SUGI Beginning Tutorials
5. 5
Colorful Output
Obs x y z
1 one 2 3
2 four 5 6
Creating a Style Template from Scratch
Creating a Style Template from scratch is
done using PROC TEMPLATE, and a DEFINE
statement quite like creating a style with a
PARENT statement. The main difference
between creating one with a parent and one
from scratch is using STYLE statements in the
place of CLASS statements. For example,
define style newstyle;
style cellcontents /
fontfamily="arial"
fontweight=medium
backgroundcolor=blue
…
This is recommended for experienced users
that have sufficient experience creating styles
from parents and playing with its contents.
There are too many style options to list in this
section, but some of the most common
options have been highlighted in the previous
example, and the code provided can be
expanded to fit many other options.
5.2. Table Templates
Table templates are generally stored under
the name of the procedure they are applied
to. For now, we will look at the default
template for printing a data set. When
running a PROC PRINT step, there are various
ways to personalize a data table. Given the
same data set from Section 5.1, this is what
the data would look like, using the template
BASE.TEMPLATE.TABLE.
x y z
one 2.000000 3.000000
four 5.000000 6.000000
Using PROC TEMPLATE, we can create a new
template named MYTABLE based off of this
default template.
proc template;
define table mytable;
parent = Base.Template.Table;
end;
run;
Suppose we would like to change the header
text. We would need to enter a DEFINE
HEADER statement inside the DEFINE TABLE
statement to add the header to the table
template, as such.
proc template;
define table mytable;
parent = Base.Template.Table;
define header myheader;
text 'Example';
end;
end;
run;
This produces the same formatting as before,
but now there is a header on the table.
Example
x y z
one 2.000000 3.000000
four 5.000000 6.000000
For more options, check the following section.
Next, we would like to change the setup of the
columns. By adding a COLUMN statement, we
can name columns that will appear in the
table if the data exists in SAS. Adding
parentheses can make multiple variables
appear in the same cells.
SUGI Beginning Tutorials
SUGI Beginning Tutorials
6. 6
proc template;
define table mytable;
parent = Base.Template.Table;
define header myheader;
text 'Example';
end;
column x (y z);
end;
run;
Example
x y
one 2.000000
3.000000
four 5.000000
6.000000
Creating Table Templates from Scratch
Without the PARENT statement, we have
more settings to specify. By adding
statements between the DEFINE TABLE and
corresponding END statement, we can change
headers, footers, colors, and column settings
in a template.
Some of the statements available are
CELLSTYLE, COLUMN, DEFINE (to create a
column or style template within the table
template), FOOTER, HEADER, NOTES, and
TRANSLATE. The COLUMN statement names
the columns that will appear in the output
table, if variables of these names exist.
Here is one example of a table template which
contains STYLE statements, a COLUMN
statement, and defines a header, footer, and
column template.
proc template;
define table mytable;
style = {borderwidth=1
background=green};
column x y z;
define header main;
style = {color=purple};
end;
define column x;
style = {color=green};
header = main;
end;
define footer tail;
style = {color=red};
text 'Adding text to the end
of the table';
end;
end;
run;
Applying this template to the same data set
from earlier, we get this output.
x y z
one 2.000000 3.000000
four 5.000000 6.000000
Adding text to the end of
the table
6. Applying Templates to Various
Destinations
Calling a destination‐centric template
requires the use of SAS's ODS feature.
The following code will allow you to
recreate the output in this paper. We
apply the custom style template
named FANCY and the custom table
template named MYTABLE.
6.1. RTF Output
Users can output to rich‐text format using the
following ODS commands:
Style template:
ods rtf file =
‘destinationfilename.rtf'
style = fancy;
proc print data = dataset_name;
run;
ods rtf close;
SUGI Beginning Tutorials
7. 7
Table template:
ods rtf file =
‘destinationfilename.rtf';
proc sgrender data = dataset_name
template = mytable;
run;
ods rtf close;
6.2 HTML Output
Users can output to html format using the
following ODS commands:
Style template:
ods html body='fancy.htm'
style=fancy;
proc print data = dataset_name;
run;
ods html close;
Table template:
ods html;
body = "table.htm";
proc sgrender data = dataset_name
template = mytable;
run;
ods html close;
6.3 PDF Output
Users can output to pdf format using the
following ODS commands:
Style template:
ods pdf file =
‘destinationfilename.pdf'
style = fancy;
proc print data = dataset_name;
run;
ods pdf close;
Table template:
ods pdf file =
‘destinationfilename.pdf';
proc sgrender data = dataset_name
template = mytable;
run;
ods pdf close;
7. Conclusion
Templates are a basis to everything done in
SAS. When using templates to their maximum
potential, it is possible to create very eye
catching tables and styles that draw in the
attention of the viewers to important
statistics or outliers. They can be applied to
various destinations to best suit your needs.
Templates are an advanced procedure, but
can produce satisfying results with fewer
lines of code than other methods.
8. References
Delaney, Kevin. "Pure Evil, or Just
Misunderstood? An Interview with PROC
TEMPLATE". SUGI 29: Data Presentation.
Centers for Disease Control and Prevention,
Atlanta, GA. Web. 16 Nov 2014.
Gupta, Sunil. "Using Styles and Templates to
Customize SAS® ODS Output". SUGI 29:
Tutorials. Gupta Programming, Simi Valley,
CA. Web. 16 Nov 2014.
Haworth, Lauren. "PROC TEMPLATE: The
Basics". SUGI 31: Hands‐on Workshops.
Genentech, Inc., South San Francisco, CA.
Web. 16 Nov 2014.
Hoevenaars M., & Baljet M. “Creating RTF‐
Output Using ODS and PROC TEMPLATE”.
Blue Gum Data Analysis, 2001. Web. 9 Nov.
2014.
Janet Stuelpner. “Proc Template: A Place to
Start”. SAS Institute Inc., 2008. Web. 9 Nov.
2014.
SAS. "TEMPLATE Procedure: Creating a Style
Template". support.sas.com. SAS Institute Inc.,
2014. Web. 16 Nov 2014.
SAS. "TEMPLATE Procedure: Managing
SUGI Beginning Tutorials
SUGI Beginning Tutorials