ODS Graphics Template Modification

Editing Templates

You can modify the format and appearance of a particular graph by doing the following:

  • Modify its template definition (source program).

  • Submit the revised template to create a new compiled template, which is stored in a template store.

  • Ensure that the ODS template search path includes the template store that contains your new template.

Template stores are designated read-only (such as Sashelp.Tmplmst) or updatable (such as Sasuser.Templat).

If you view the templates in an updatable template store from the Templates window, you can select Open or Edit from the pop-up menu. Either the Template Browser or Template Editor window opens. In the Template Editor window, you can make changes and submit the code directly. For read-only templates or when you select Open, the Template Browser window opens and you must copy the definition to an editor window to make changes. Since templates supplied by SAS are in the read-only Sashelp library, an easy way to obtain an editable program file is to use the SOURCE statement with the FILE= option in PROC TEMPLATE to write the template definition to a file as follows:

proc template;
   source Stat.REG.Graphics.ResidualPlot / file="residtpl.sas";

By default, the file is saved in the SAS current folder. Alternatively, you can omit the slash and the FILE= option and copy and paste the source from the SAS log into an editor. Either way, you must add a PROC TEMPLATE statement before the generated source statements and optionally a RUN statement after the END statement before you submit your modified definition.

Graph templates are self-contained and do not support inheritance (via the PARENT= option) as do table templates. Consequently, the EDIT statement in PROC TEMPLATE is not supported for graph templates.

Here are some important points about what you can and cannot change in a template supplied by SAS while preserving its overall functionality:

  • Do not change the template name. A statistical procedure can access only a predefined list of templates. If you change the name, the procedure cannot find your template. You must keep the original name and make sure that it is in a template store that is searched before Sashelp.Tmplmst. You control this with the ODS PATH statement (see the section The Default Template Stores and the Template Search Path in ChapterĀ 21: Statistical Graphics Using ODS, the section Saving Customized Templates, and subsequent sections for more information about the template search path and the ODS PATH statement).

  • Do not change the names of columns. The underlying data object contains predefined column names that you must use. Be very careful if you change how a column is used in a template. Usually, columns are not interchangeable.

  • Do not change the names of DYNAMIC variables. Procedures set values only for a predefined list of dynamic variables. Changing dynamic variable names can lead to runtime errors. Do not add dynamic variables, because the procedure cannot set their values. A few procedures document additional dynamic variables that can be defined in the template if you want to add more information to the output, such additional statistics in an inset table.

  • Do not change the names of statements (for example, from a SCATTERPLOT to a NEEDLEPLOT or other type of plot).

You can change any of the following:

  • You can add macro variables that behave like dynamic variables. They are resolved at the time that the statistical procedure is run, and not at the time that the template is compiled. They are defined with an MVAR or NMVAR statement at the beginning the template. You can set the value of each macro variable with a %LET statement before the statistical procedure is run. See Example 22.5. You can also move a variable from a DYNAMIC statement to an MVAR or NMVAR statement if you want to set it yourself rather than letting the procedure set it.

  • You can change the graph size.

  • You can change graph titles, footnotes, axis labels, and any other text that appears in the graph.

  • You can change which plot features are displayed.

  • You can change axis features, such as grid lines, offsets, view ports, tick value formatting, and so on.

  • You can change the content and arrangement of insets (small tables of statistics embedded in some graphs).

  • You can change the legend location, contents, border, background, title, and so on.

See the SAS Graph Template Language: Reference for information about the syntax of the statements in the Graph Template Language.