Example 15.10: Using the TEMPLATE Procedure to Customize Output

You can use the TEMPLATE procedure to modify the appearance of your
displayed ODS tables.
The following example, similar to that given in Olinger and Tobias
(1998), creates output data sets using the ODS OUTPUT statement,
modifies a template using PROC TEMPLATE, and displays the output data
sets using the modified template.

The data set comes from a preclinical drug experiment
(Cole and Grizzle 1966). In order to study the effect of two
different drugs on histamine levels in the blood, researchers
administer the drugs
to 13 animals, and the levels of
histamine in the animals' blood is measured after 0, 1, 3, and 5
minutes. The response variable is the logarithm of the histamine
level. The following statements create a SAS data set named
Histamine that contains the experimental data.

In the analysis that follows, the GLM procedure is invoked to perform a
repeated measures analysis, naming the drug and depletion status as
between-subject factors in the MODEL statement and naming
post-administration measurement time as the within-subject factor
(for more information on this study and its analysis, see Example 7 in
Chapter 30, "The GLM Procedure").

The following ODS statement requests that two ODS tables be written to
SAS data sets called HistWithin and HistBetween.
The SAS listing is closed so that no output is displayed. The
GLM procedure is invoked and the model is fit.

All of the multivariate test results appear in the HistWithin data
set. This is because all multivariate test tables are named
"MultStat," although they occur in different directories in the output
directory hierarchy.

Note that, even though there are also other tables named "ModelANOVA,"
the preceding ODS OUTPUT statement ensures that only the
between-subject ANOVA appears in the HistBetween data set.
The specific table is selected because of
the additional specification of the partial path ("BetweenSubjects") in
which it occurs. For more information on names and qualified path
names, see the discussion in the section "Using the Output Delivery System".

In the following statements, a new data set, temp1, is created
to contain the two data sets output in the preceding GLM run. They are
displayed with no further processing.

In order to reduce the amount of information displayed in Output 15.10.1,
this example creates the following data set, HistTests.
Only the observations from the raw data sets that are needed for interpretation
are included.
The variable Hypothesis in the HistWithin
data set is renamed to Source, and the NumDF variable is
renamed DF. The renamed variables correspond to the
variable names found in the HistBetween data set.

The amount of information contained in the HistTests is
appropriate for interpreting the analysis (Output 15.10.2).
However, you can further
modify the presentation of the data by applying a template to this
combined test data. A template specifies how data should be
displayed. The output from previous ODS TRACE ON statements (for
example, Output 15.4.2) shows that each table has an associated
template as well as a name. In particular, the template associated
with PROC GLM's ANOVA table is called 'Stat.GLM.Tests'.

You can use
the 'Stat.GLM.Tests' template to display the SAS data set HistTests, as follows:

The ODS= option in the FILE statement enables you to use the DATA step
to display a data set as a table. You do this by specifying data
columns and associated attributes, such as the template specification.

The PUT statement contains the _ODS_ keyword. The keyword instructs
the PUT statement to send the data values for all columns (as defined
in the ODS= option in the FILE statement) to the open ODS destinations.
For more information on using ODS in the DATA step, refer to
The Complete Guide to the SAS Output Delivery System.

The data set contains the appropriate information, and it is
presented in an easily understandable format, using the
'Stat.GLM.Tests' template.

Customizing Your Output

Suppose that you now want to modify the template used to
format the ANOVA tables in order to emphasize significant effects.
The following statements provide an example of how you can use the
TEMPLATE procedure to

redefine the format for the SS and Mean Square columns

include the table title and footnote in the body of the table

translate the missing values for SS and Mean Square in the rows
corresponding to multivariate tests to asterisks
(to refer to the footnote)

add a column depicting the level of significance

For detailed information on using the TEMPLATE procedure, refer to the
chapter titled "The Template Procedure" in
The Complete Guide to the SAS Output Delivery System.

The Dw.s format, used in the preceding statements to redefine
the SS and Mean Square columns, writes
numbers in similar ranges with the same number of decimal places. In
the format specification, w represents the width of the field
and s represents the number of significant digits. Refer to the
chapter on formats in SAS Language Reference: Dictionary for
detailed information.

The following statements display the HistTests data set using the
customized template. The results are displayed in Output 15.10.4.