TEMPLATE Procedure: Creating Table Templates

Example 1: Editing a Table Template That a SAS Procedure Uses

Features:

EDIT statement

Header attributes:
JUST=
STYLE=
Table attributes:
DOUBLE_SPACE=
OVERLINE=
UNDERLINE=
Other features:
Other ODS features:
ODS LISTING statement
ODS SELECT statement
DELETE statement
Data set: Exprev

Details

This example customizes the table template for the Moments output object from PROC UNIVARIATE. The first program uses the table template that SAS supplies to generate both LISTING output and HTML output of the Moments object.
Note: This example uses filenames that might not be valid in all operating environments. To successfully run the example in your operating environment, you might need to change the file specifications. See ODS HTML Statements for Running Examples in Different Operating Environments.
The second program does the following:
  • creates and edits a copy of the default table template
  • edits a header within the table template
  • sets column attributes to enhance the appearance of both the HTML and the LISTING output

Program 1: Using the Default Table Template That SAS Provides

options nodate pageno=1 pagesize=60 linesize=72;
ods listing;
ods select moments;
proc univariate data=exprev mu0=3.5;
   var Quantity;
title "Default Moments Table";
run;
ods listing close;

Program Description

Set the SAS system options. The OPTIONS statement controls several aspects of the LISTING output.
options nodate pageno=1 pagesize=60 linesize=72;
Create the LISTING output.The ODS LISTING statement opens the LISTING destination and creates LISTING output.
ods listing;
Select the output objects for the report.The ODS SELECT statement sends one output object, Moments, to the open ODS destinations. Both the LISTING and the HTML destinations are open.
To learn the names of the output objects, run the procedure with the ODS TRACE ON statement in effect. For more information see ODS TRACE Statement.
ods select moments;
Compute the descriptive statistics for one variable. PROC UNIVARIATE computes the univariate statistics for one variable, Quantity. It uses the default table template, Base.Univariate.Moments from the template store Sashelp.Tmplmst.
proc univariate data=exprev mu0=3.5;
   var Quantity;
title "Default Moments Table";
run;
Stop the creation of the LISTING output. The ODS LISTING CLOSE statement closes the LISTING destination and all the files that are associated with it. You must close the destination before you can view the output.
ods listing close;

Output from Program 1

LISTING Output from PROC UNIVARIATE (Default Moments Table)
LISTING Output from PROC UNIVARIATE (Default Moments Table)
HTML Output from PROC UNIVARIATE (Default Moments Table)
Default HTML Output from PROC UNIVARIATE (Default Moments Table)

Program 2: Using a Customized Table Template

ods path sasuser.templat(update) sashelp.tmplmst(read);
proc template;
   edit base.univariate.moments;
   double_space=on;
   underline=on;
   overline=on; 
   label="Custom Moments";
   double_space=on; 
   style=data{color=orange fontstyle=italic};
   edit head;
         style=header{color=green fontstyle=italic};
         just=left;
     end;
   end;
run;
ods listing;
ods select moments;
proc univariate data=exprev mu0=3.5;
   var Quantity;
title "Custom Moments Table";
run;
ods listing close;
proc template;
delete base.univariate.moments;
end;
title;

Program Description

Specify the search path in order to locate the table template. The ODS PATH statement specifies which locations to search for definitions or templates that were created by PROC TEMPLATE, as well as the order in which to search for them. The statement is included to ensure that the example works correctly. However, if you have not changed the path, you do not need to include this statement because it specifies the default path.
ods path sasuser.templat(update) sashelp.tmplmst(read);
Create a modified table template Base.Univariate.Moments. The EDIT statement looks in the available template stores for a table template called Base.Univariate.Moments. By default, it first looks in Sasuser.Templat, but it finds nothing. Next, it looks in Sashelp.Tmplmst, which contains the table templates that SAS provides. Because the EDIT statement can read this template, this is the one that it uses. The program does not specify a destination for the edited template, so PROC TEMPLATE writes to the first template store in the path that it can write to, which is Sasuser.Templat. Therefore, it creates a table template of the same name as the original one in Sasuser.Templat.
To learn the name of the table template that a procedure uses, run the procedure with the ODS TRACE ON statement in effect.For more information see ODS TRACE Statement.
proc template;
   edit base.univariate.moments;
Specify changes to the Moments output object for the LISTING output. These three table attributes affect the presentation of the Moments output object in the listing output. They have no effect on its presentation in the HTML output. DOUBLE_SPACE= creates double spaces between the rows of the output object. OVERLINE= and UNDERLINE= draw a continuous line before the first row of the table and after the last row of the table.
   double_space=on;
   underline=on;
   overline=on; 
Specify changes to the Moments output object for the HTML destination. These three table attributes affect the presentation of the Moments output object in the HTML output. DOUBLE_SPACE=ON specifies to double space between the rows of the table. The STYLE= statements specify a color and font style for the cell data. The LABEL= attribute changes the label that appears in the Results window from “Moments” to “Custom Moments”.
   label="Custom Moments";
   double_space=on; 
   style=data{color=orange fontstyle=italic};
Modify a table element. The following EDIT statement edits the table element Head within the table template.
   edit head;
Modify the appearance of the header. The STYLE= attribute alters the style element that produces the Head table element. The style element Header is defined in the default style, Styles.HTMLBlue. Many procedures, including PROC UNIVARIATE, use this style element to produce headers for tables and columns. In this case, the STYLE= attribute specifies green for the foreground color and italic for the font style. All other attributes that are included in Header remain in effect. The STYLE= attribute affects only the HTML output.
For information about viewing a style, see Styles That Are Shipped with SAS Software. For a table of style element names, see ODS Style Elements.
         style=header{color=green fontstyle=italic};
Left-justify the header text. The JUST= attribute left-justifies the text of the header in both the listing and the HTML output.
         just=left;
Stop the editing of the table element and the table template. The first END statement ends the editing of the table element Head. The second END statement ends the editing of the table Base.Univariate.Moments.
     end;
   end;
run;
Create the LISTING output.The ODS LISTING statement opens the LISTING destination and creates LISTING output.
ods listing;
Select the output objects for the report. The ODS SELECT statement sends one output object, Moments, to the open ODS destinations. Both the LISTING and the HTML destinations are open. To learn the names of the output objects, run the procedure with the ODS TRACE ON statement in effect.
ods select moments;
Compute the descriptive statistics for one variable. PROC UNIVARIATE computes the univariate statistics for one variable, Quantity. The actual results of the procedure step are the same in this case, but they are presented differently because the procedure uses the edited table template. It does so because when it looks for Base.Univariate.Moments, it looks in the first template store in the path, Sasuser.Templat. If you wanted to use the table template that is supplied by SAS, you would have to change the path with the ODS PATH statement.
See also: ODS PATH Statement.
proc univariate data=exprev mu0=3.5;
   var Quantity;
title "Custom Moments Table";
run;
Stop the creation of the LISTING output. The ODS LISTING CLOSE statement closes the LISTING destination and all the files that are associated with it. You must close the destination before you can view the output.
ods listing close;
Remove the customized moments table template from Sasuser.Templat.The DELETE statement removes the customized moments table that was created in this example. When using the DELETE statement, ODS looks for base.univariate.moments in Sasuser.Templat first. If it is there, it will delete it. If not, it will search Sashelp.Tmplmst.
proc template;
delete base.univariate.moments;
end;
title;

Output for Program 2

LISTING Output (Customized Moments Table) from PROC UNIVARIATE
LISTING Output (Customized Moments Table) from PROC UNIVARIATE
Customized HTML Output (Customized Moments Table) from PROC UNIVARIATE (Viewed with Microsoft Internet Explorer)
Customized HTML Output (Customized Moments Table) from PROC UNIVARIATE (Viewed with Microsoft Internet Explorer)