Graph Template Modification Macro

You can use the %ModTmplt autocall macro to insert BY line information, titles, and footnotes in ODS Graphics. You can also use it to remove titles and perform other template modifications. See Kuhfeld (2009) for more information about this macro.

You do not have to include autocall macros (for example, with a %include statement). You can call them directly once they are properly installed. If your site has installed the autocall libraries supplied by SAS and uses the standard configuration of SAS supplied software, you need to ensure that the SAS system option MAUTOSOURCE is in effect to begin using the autocall macros. For more information about autocall libraries, see the SAS Macro Language: Reference. For details about installing autocall macros, consult your host documentation.

The %ModTmplt macro has the following options:

BY=by-variable-list

specifies the list of BY variables. Also see BYLIST=. When graphs are produced (by default or when the STEPS= value contains 'G'), you must specify the BY= option. Otherwise, when you are only modifying the template, you do not need to specify the BY= option. Note: This option has been rendered obsolete by the BYLINE= option in the ODS GRAPHICS statement.

BYLIST=by-statement-list

specifies the full syntax of the BY statement. You can specify a full BY statement syntax including the DESCENDING or NOTSORTED options. If only BY variables are needed, specify only BY=. If you also need options, then specify the BY variables in the BY= option and the full syntax in the BYLIST= option (for example, specify BY=A B and BYLIST=A DESCENDING B). Note: This option has been rendered obsolete by the BYLINE= option in the ODS GRAPHICS statement.

DATA=SAS-data-set

specifies the input SAS data set. If you do not specify the DATA= option, the macro uses the most recently created SAS data set.

FILE=filename

specifies the file in which to store the original templates. This is a temporary file. You can specify either a quoted file name or the name from a FILENAME statement that you provide before you call the macro. The default is "template.txt".

OPTIONS=options

specifies one or more of the following options (case is ignored):

LOG

displays a note in the SAS log when each BY group has finished.

FIRST

adds the ENTRYTITLE or ENTRYFOOTNOTE statements as the first titles or footnotes. By default, the statements are added after the last titles or footnotes. Most graph templates provided by SAS do not use footnotes; so this option usually affects only entry titles.

NOQUOTES

specifies that the values of the system titles and footnotes are to be moved to the ENTRYTITLE or ENTRYFOOTNOTE statements without the outer quotation marks. With OPTIONS=NOQUOTES, you can specify options in the titles or footnotes in addition to the text. However, you must ensure that you quote the text that provides the actual title or footnote.

The following is an example of an ordinary footnote:

footnote "My Footer";

With this FOOTNOTE statement and without OPTIONS=NOQUOTES, the macro creates the following ENTRYFOOTNOTE statement:

entryfootnote "My Footer";

The following footnotes are used with OPTIONS=NOQUOTES:

footnote 'halign=left "My Footer"';
footnote2 '"My Second Footer"';

With these FOOTNOTE statements and OPTIONS=NOQUOTES, the macro creates the following ENTRYFOOTNOTE statements:

entryfootnote halign=left "My Footer";
entryfootnote "My Second Footer";
REPLACE

replaces the unconditionally added entry titles and entry footnotes in the templates (those that are not part of IF or ELSE statements) with the system titles and footnotes. The system titles and footnotes are those that are specified in the TITLE or FOOTNOTE statements. You can instead use the TITLES=SAS-data-set option to specify titles and footnotes with a data set. If OPTIONS=REPLACE is specified, then OPTIONS=TITLES is ignored.

SOURCE

displays the generated source code. By default, the template source code is not displayed.

TITLES

displays the system titles and footnotes with the graphs. The system titles and footnotes are those that are specified in the TITLE or FOOTNOTE statements. You can instead use the TITLES=SAS-data-set option to specify titles and footnotes with a data set. If you also specify OPTIONS=FIRST, the system titles and footnotes are inserted before the previously existing entry titles and entry footnotes in the templates. Otherwise, they are inserted at the end.

You can specify OPTIONS=TITLES or OPTIONS=REPLACE, or insert BY lines, or do both. If you do both, and you do not like where the BY line is inserted relative to your titles and footnotes, just specify OPTIONS=NOQUOTES and _ByLine0 to place the BY line wherever you choose. The following TITLE statements illustrate:

title1 '"My First Title"';
title2 '_byline0';
title3 '"My Last Title"';

Also, you can embed BY information in a title or a footnote, again with OPTIONS=NOQUOTES. For example:

title '"Spline Fit By Sex, " _byline0';

When _ByLine0 is specified in any of the titles or footnotes, then the usual BY line is not added.

The following example removes all titles and footnotes:

footnote;
title;
%modtmplt(options=replace, template=Stat.Transreg.Graphics, steps=t)
STATEMENT=entry-statement-fragment

specifies the statement that contains the BY line that gets added to the template along with any statement options. The default is Statement=EntryFootNote halign=left TextAttrs=GraphValueText. Other examples include:

Statement=EntryTitle
Statement=EntryFootNote halign=left TextAttrs=GraphLabelText
STEPS=steps

specifies the macro steps to run. Case and white space are ignored. the macro modifies the templates (when 'T' is specified), produces the graphs for each BY group (when 'G' is specified), and deletes the modified templates (when 'D' is specified). The default is STEPS=TGD. You can instead have it perform a subset of these three tasks by specifying a subset of terms in the STEPS= option.

When you use the %ModTmplt macro to add BY lines, you usually do not need to delete the templates before you run your procedure again in the normal way. The template modification inserts the BY line through a macro variable and an MVAR statement. When the macro variable _ByLine0 is undefined, the ENTRYTITLE or ENTRYFOOTNOTE statement drops out as if it were not there at all.

STMTOPTS1=n $\; $ ADD | REPLACE | DELETE | BEFORE | AFTER $\; $statement-name $\; $ <options>
STMTOPTS2=n $\; $ ADD | REPLACE | DELETE | BEFORE | AFTER $\; $statement-name $\; $ <options>
STMTOPTS3=n $\; $ ADD | REPLACE | DELETE | BEFORE | AFTER $\; $statement-name $\; $ <options>
STMTOPTS4=n $\; $ ADD | REPLACE | DELETE | BEFORE | AFTER $\; $statement-name $\; $ <options>
STMTOPTS5=n $\; $ ADD | REPLACE | DELETE | BEFORE | AFTER $\; $statement-name $\; $ <options>
STMTOPTS6=n $\; $ ADD | REPLACE | DELETE | BEFORE | AFTER $\; $statement-name $\; $ <options>
STMTOPTS7=n $\; $ ADD | REPLACE | DELETE | BEFORE | AFTER $\; $statement-name $\; $ <options>
STMTOPTS8=n $\; $ ADD | REPLACE | DELETE | BEFORE | AFTER $\; $statement-name $\; $ <options>
STMTOPTS9=n $\; $ ADD | REPLACE | DELETE | BEFORE | AFTER $\; $statement-name $\; $ <options>
STMTOPTS10=n $\; $ ADD | REPLACE | DELETE | BEFORE | AFTER $\; $statement-name $\; $ <options>

These ten options add or replace options in up to 10 selected statements. The following example illustrates:

%modtmplt(template=Stat.glm.graphics.residualhistogram, steps=t,
          stmtopts1=.  add  discretelegend  autoalign=(topleft),
          stmtopts2=1  add  densityplot     legendlabel='Normal Density',
          stmtopts3=2  add  densityplot     legendlabel='Kernel Density',
          stmtopts4=1  add  overlay         yaxisopts=(griddisplay=on)
                            yaxisopts=(label='Normal and Kernel Density'))

proc glm plots=diagnostics(unpack) data=sashelp.class;
   model weight = height;
run;

%modtmplt(template=Stat.glm.graphics.residualhistogram, steps=d)

These options require you to specify a series of values. The first value is the statement number (or missing to modify options on all statements that match the statement name). The second value is: ADD, REPLACE, DELETE, BEFORE, or AFTER. When the second value is ADD or REPLACE, it controls whether you add new options or replace existing options. Alternatively, the second value can be BEFORE or AFTER to add a new statement before or after the named statement. When the value is DELETE, the corresponding statement is deleted. The third value is a statement name. All remaining options are options for the statement named by the third value (with ADD and REPLACE) or for a new statement (with BEFORE and AFTER). In the STMTOPTS1= example, an option is added to all DISCRETELEGEND statements. In the STMTOPTS2= example, an option is added to the first DensityPlot statement. In the STMTOPTS4= example, an option is added to the LAYOUT OVERLAY statement. In most cases, the statement name is the first name that begins the statement. The LAYOUT statement is an exception. In the case of layouts, specify the second name (OVERLAY, GRIDDED, LATTICE, and so on) for the third value. Note that a statement such as if (expression) EntryTitle...; is an IF statement not an ENTRYTITLE statement.

If an option is specified multiple times on a GTL statement, the last specification overrides previous specifications. Hence, you do not need to know and respecify all of the options. You can just add an option to the end, and it overrides the previous value. You can use these options only to modify statements that contain a slash, and only to modify the options that come after the slash. Note that in STMTOPTS4=, the YAXISOPTS= option is specified twice. It could have been equivalently specified once as follows:

yaxisopts=(griddisplay=on label='Normal and Kernel Density'))

The actual specification adds the GRIDDISPLAY=ON to the Y axis options (which by default has only a label specification). The old label is unchanged until the LABEL= option in the second YAXISOPTS= specification overrides it. In other words, YAXISOPTS=(GRIDDISPLAY=ON) augments the old YAXISOPTS= option; it does not replace it.

The following steps delete the legend and instead provide a footnote:

%modtmplt(template=Stat.glm.graphics.residualhistogram, steps=t,
          stmtopts1=. delete discretelegend,
          stmtopts2=1 after  begingraph entryfootnote
                      textattrs=GraphLabelText(color=cx445694) 'Normal  '
                      textattrs=GraphLabelText(color=cxA23A2E) 'Kernel')

proc glm plots=diagnostics(unpack) data=sashelp.class;
   model weight = height;
run;

%modtmplt(template=Stat.glm.graphics.residualhistogram, steps=d)
TEMPLATE=SAS-template

specifies the name of the template to modify. You can specify just the first few levels to modify a series of templates. For example, to modify all of PROC REG’s graph templates, specify TEMPLATE=Stat.Reg.Graphics. This option is required.

TITLES=SAS-data-set

specifies a data set that contains titles or footnotes or both. By default, when the system titles or footnotes are used (when OPTIONS=TITLES or OPTIONS=REPLACE is specified), PROC SQL is used to determine the titles and footnotes. You can instead create this data set yourself so that you can set the graph titles independently from the system titles and footnotes. The data set must contain two variables: Type (Type='T' for titles and Type='F' for footnotes), and Text, which contains the titles and footnotes. Other variables are ignored. Specify the titles and footnotes in the order in which you want them to appear.

TITLEOPTS=entry-statement-options

specifies the options for system titles and footnotes. For example, you can specify the HALIGN= and TEXTATTRS= options as in the STATEMENT= option. By default, no title options are used. With OPTIONS=NOQUOTES, you can specify options individually.