Biostat Macro Library

Mass Production of Standard Error Plots

%StdErrPlot and %StdErrPlotY reside in the departments SAS Macro Library and are enabled with the following SAS statements:

Libname biostat '\\BIO2\example\SASMacrosWindows';
Options Mstored SasMstore=biostat;

%StdErrPlot and %StdErrPlotY calculate and plot the standard error bars of the changes from baseline, by treatment, for each variable listed. Visits that have <20% of enrolled subjects are automatically dropped. Available plot styles are BlackWhite, Color (white background) or PowerPoint (blue frame, gold trim, black background). Graphs are displayed individually and 2, 4, 9 or 16 to a page. “Jitter” allows you to space out the error bars so they are not printed directly on top of each other.

Syntax:
%StdErrPlot(dataset,who,group,visit,baseline,start,stop,by,jitter,varlist,style,replay);
%StdErrPlotY(dataset,who,group,visit,baseline,start,stop,by,jitter,ystart,ystop,yby,varlist,style,replay);
    dataset:   Dataset to use.
    who:       Subject ID.
    group:     Group/Treatment(Numeric).
    visit:        X axis/Time/Week/Month(Numeric).
    baseline:  Baseline visit(Numeric Constant).
    start:        X axis Begining(Numeric Constant).
    stop:        X axis Ending(Numeric Constant).
    by:           X axis Step(Numeric Constant).
    jitter:        Space between standard error bars(Numeric Constant).
    varlist:      List of variables to Boxplot(Numeric).
    style:        BlackWhite, Color or PowerPoint.
    replay:      Number of graphs to display on a page(2, 4, 9 or 16).
    ystart:       Y axis Begining(Numeric Constant).
    ystop:       Y axis Ending(Numeric Constant).
    yby:          Y axis Step(Numeric Constant).

Example:
%StdErrPlot(work.A,id,treatment,visit,0,-2,12,2,0.1, A B C D E,Color,9);
%StdErrPlotY(work.A,id,treatment,visit,0,-2,12,2,0.1,-15,20,5,A B C D E,Color,9);

The default colors may be changed by defining a macro variable named “Colors”:

%Let Colors=Background_color Foreground_color Group1_color Group2_color Group3_color…;
%Let Colors=Blue Yellow Green Red Purple Black;

The default font of centx may be changed on all text by defining a macro variable named “Font”:

%Let Font=Simplex;

The position of the legend may be changed by defining a macro variable named "LegendOption":

%Let LegendOption=Position=(Inside Top Left) Across=2 Down=2;

This procedure creates a graphics catalog named “work.mplot”. The graphics catalog may be cleared by closing the graph window and running the following code.

Proc Datasets Library=work Memtype=Catalog;
    Delete mplot;
Run;

If you are running SAS interactively, this procedure will always replay the first set of graphs in the catalog. You may wish to reset the catalog between each procedure call.

Output:

%StdErrPlotY allows you to fix the Y axis to compare similar scales.

*Usage Trick: If you have a few sets of graphs with fixed Y axis, they may be replayed together by padding
the variable list in the last call to %StdErrPlotY:

%StdErrPlotY(work.A,id,treat,visit,0,-2,12,2,0.1,-15,20,5,A1 A2,Color,9);
Creates two graphs and saves them in a SAS catalog.

%StdErrPlotY(work.A,id,treat,visit,0,-2,12,2,0.1,-4,16,4,B1 B2 B3,Color,9);
Creates three graphs and saves them in the SAS catalog. The catalog now has five graphs.

%StdErrPlotY(work.A,id,treat,visit,0,-2,12,2,0.1,-3,9,1,C1 C2 C3 C3 C3 C3 C3 C3,Color,9);
The above statement creates eight graphs and saves them in a SAS catalog. The catalog now has 13 graphs. The last five are obviously repeated. Since there are 8 variables in the variable list, the macro will only replay the first 8 graphs from the catalog and ignore the last 5 repeated graphs. As long as the catalog is not cleared, StdErrPlotY can replay all the graphs saved in the catalog.