To view the Measures code, double-click Measures. The Measures template opens in
the Template Browser window. You can then copy and paste the code into the Editor
window for customization.
Output 34.3 Measure Templates That Are Supplied by SAS
You can create your own table template or modify an existing one by using the
TEMPLATE procedure. The following is a simplified form of the TEMPLATE
procedure:
PROC TEMPLATE;DEFINE table-definition;HEADER header(s);COLUMN
column(s);END;
The DEFINE statement creates the table template that serves as the template for writing
the output. The HEADER statement specifies the order of the headings, and the
COLUMN statement specifies the order of the columns. The arguments in each of these
statements point to routines in the program that format the output. The END statement
ends the table template.
The following example shows how to use PROC TEMPLATE to create customized
HTML and PDF output. You can first copy the SAS template code that is supplied by
SAS using the method described in Output 34.3 on page 672. In this example, the SAS
672 Chapter 34 Understanding and Customizing SAS Output: The Output Delivery System (ODS)
program creates a customized table template for the Basic Measures output table from
PROC UNIVARIATE. The following customized version shows that
the “Measures of Variability” section precedes the “Measures of Location” section
column headings are modified
font colors are modifies
statistics are displayed in a bold, italic font with a 7.3 format, and a specific font
color.
Create the new template.
1 options nodate nonumber;
2 proc template;
3 define table base.univariate.Measures;
4 header h1 h2 h3;
5 column VarMeasure VarValue LocMeasure LocValue;
6 define h1;
text "Basic Statistical Measures";
style=data{color=orange fontstyle=italic};
spill_margin=on;
space=1;
end;
6 define h2;
text "Measures of Variability";
start=VarMeasure;
end=VarValue;
end;
6 define h3;
text "Measures of Location";
start=LocMeasure;
end=LocValue;
end;
7 define LocMeasure;
print_headers=off;
glue=2;
space=3;
style=rowheader;
end;
7 define LocValue;
print_headers=off;
space=5;
format=7.3;
style=data{font_style=italic font_weight=bold color=red};
end;
7 define VarMeasure;
print_headers=off;
glue=2;
space=3;
Customizing ODS Output 673
style=rowheader;
style=data{font_style=italic font_weight=bold color=purple};
end;
7 define VarValue;
print_headers=off;
format=7.3;
style=data{font_style=italic font_weight=bold color=blue};
end;
8 end;
9 run;
The following list corresponds to the numbered items in the preceding program:
1
The NODATE and NONUMBER options affect the Printer output. None of the
options affects the HTML output.
2
PROC TEMPLATE begins the procedure for creating a table.
3
The DEFINE statement creates the table template base.univariate.Measures in
SASUSER.
The base.univariate.Measures table template that SAS provides is stored in a
template store in the SASHELP library. (See Output 34.2 on page 670.)
4
The HEADER statement determines the order in which the table template uses the
headings, which are defined later in the program.
5
The COLUMN statement determines the order in which the variables appear. PROC
UNIVARIATE names the variables.
6
These DEFINE blocks define the three headings and specify the text to use for each
heading. By default, a heading spans all columns. This is the case for H1. H2 spans
the variables VarMeasure and VarValue. H3 spans LocMeasure and LocValue.
7
These DEFINE blocks specify characteristics for each of the four variables. They use
FORMAT= to specify a format of 7.3 for LocValue and VarValue. They also use
STYLE= to specify a bold, italic font for these two variables. The STYLE= option
does not affect the LISTING output.
8
The END statement ends the table template.
9
The RUN statement executes the procedure.
To view the table template that PROC TEMPLATE created, in the Templates window,
select Sasuser.Templat ð Base ð Univariate. By default, ODS searches for a table
template in SASUSER before SASHELP. When PROC UNIVARIATE calls for a table
definition by this name, ODS uses the one from SASUSER.
674 Chapter 34 Understanding and Customizing SAS Output: The Output Delivery System (ODS)
Output 34.4 User Created PROC UNIVARIATE Table Template
Create the output that uses the new template.
1 ods select BasicMeasures;
options nodate nonumber;
proc sort data=sashelp.prdsale out=prdsale;
by Country;
run;
2 ods html file='SalesFig–body.htm'
contents='SalesFig–contents.htm'
page='SalesFig–page.htm'
frame='SalesFig–frame.htm';
3 ods pdf file='odspdf_output_custom2.pdf' ;
title 'Actual Product Sales';
title2 '(millions of dollars)';
Customizing ODS Output 675

Get Step-by-Step Programming with Base SAS 9.4, Second Edition, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.