Previous Page | Next Page

Statistical Graphics Using ODS

Adding a BY Line to Graphs

You can use the %MODTMPLT macro to display in your graphs BY line information (such as Sex = ’F’ and Sex = ’M’ when the statement BY SEX is specified). The %MODTMPLT macro requires you to construct a SAS macro called %MYGRAPH, which contains the SAS procedure that needs to be run, so that the %MODTMPLT macro can call it for each BY group. The following example illustrates this usage of the macro:

proc sort data=sashelp.class out=class;
   by sex;
run;

%macro mygraph;
proc transreg data=__bydata;
   model identity(weight) = spline(height);
%mend;

%modtmplt(by=sex, data=class, template=Stat.Transreg.Graphics)

Notice that the BY and RUN statements are not specified in the %MYGRAPH macro. Also notice that you must specify DATA=__BYDATA with the procedure call in the %MYGRAPH macro and specify the real input data set in the DATA= option of the %MODTMPLT macro.

The %MODTMPLT macro outputs the specified template or templates to a file, adds an ENTRYFOOTNOTE statement with the BY line information, and then runs the %MYGRAPH macro once for each BY group. In the end, the %MODTMPLT macro deletes the modified template.

The results of the preceding statements are displayed in Figure 21.34 and Figure 21.35. The BY line is displayed as a left-justified footnote by default. You can change this with the STATEMENT= option (default: Statement=EntryFootNote Halign=Left TextAttrs=GraphValueText). For example, you can display the BY line as a centered title by specifying STATEMENT=ENTRYTITLE.

Figure 21.34 The First BY Group
The First BY Group

Figure 21.35 The Second BY Group
The Second BY Group

Previous Page | Next Page | Top of Page