FOCUS AREAS

Graphics

Matrix Display of Maximum LFT Values
Base SAS: Graph Template Language

%let graphs='.';
%let dpi=100;
%let w=5in;
%let h=5.5in;

/*----------------------------------------------------------------------------------------*/
/*  Macro for Compact Matrix                                                              */
/*  Author:  Sanjay Matange, SAS                                                          */
/*  Date:    May 15, 2011                                                                 */
/*  History: 04/09/2013/SNM - Initial                                                      */
/*                                                                                        */
/*----------------------------------------------------------------------------------------*/
%macro RefLines (x1=, x2=, y1=, y2=, pattern=);
    referenceline y=&y1 / lineattrs=(pattern=&pattern);  
    referenceline y=&y2 / lineattrs=(pattern=&pattern);
    referenceline x=&x1 / lineattrs=(pattern=&pattern);  
    referenceline x=&x2 / lineattrs=(pattern=&pattern);
%finished:
%mend RefLines;

%macro CompactMatrixMacro (
       Data=,    	      /*--Data Set Name (Required)--*/
       Var1=,             /*--Variable #1 for Matrix (Required)--*/ 
       Var2=,             /*--Variable #2 for Matrix (Required)--*/ 
       Var3=,             /*--Variable #3 for Matrix (Required)--*/ 
       Var4=,             /*--Variable #4 for Matrix (Optional)--*/ 
       Var5=,             /*--Variable #5 for Matrix (Optional)--*/
       CCL1=2,            /*--Clinical Concern Level for Var1--*/
       CCL2=2,            /*--Clinical Concern Level for Var2--*/
       CCL3=2,            /*--Clinical Concern Level for Var3--*/
       CCL4=1.5,          /*--Clinical Concern Level for Var4--*/
       CCL5=2,            /*--Clinical Concern Level for Var5--*/
       AxisValueStart=0,  /*--Axis start tick value--*/
       AxisValueEnd=4,    /*--Axis end tick value--*/
       AxisValueIncr=1,   /*--Axis tick value increment--*/
       TickValueFontSize=7, /*--Footnote Font Size--*/
       AxisLabelFontSize=8, /*--Footnote Font Size--*/
       FootnoteFontSize=10, /*--Footnote Font Size--*/
       TitleFontSize=12,   /*--Title Font Size--*/
       SubtitleFontSize=10, /*--Subtitle Font Size--*/  
       Footnote=,         /*--Graph Footnote--*/
       Footnote2=,        /*--Graph Footnote--*/
       Footnote3=,        /*--Graph Footnote--*/
       Title=,            /*--Graph title2--*/
       SubTitle=          /*--Graph Title--*/ 
);

%local  NumVar;

/*--Data set is required--*/
%if %length(&Data) eq 0 %then %do;
%put The parameter 'Data' is required - Macro Terminated.;
%goto finished;
%end;

/*--Var1, Var2 and Var3 are required--*/
%if %length(&var1) eq 0 or %length(&var2) eq 0 or %length(&var3) eq 0 %then %do;
%put The parameters 'Var1', 'Var2' and 'Var3' are required - Macro Terminated.;
%goto finished;
%end;

%let NumVar=2;

/*--Var4 is provided--*/
%if %length(&var4) ne 0 %then %do;
%let NumVar=3;
%end;

/*--Var5 is provided--*/
%if %length(&var4) ne 0 and %length(&var5) ne 0 %then %do;
%let NumVar=4;
%end;

proc template;
  define statgraph CompactMatrix_4_Out;
    dynamic _ShowUpper;
    begingraph;
      entrytitle "&title" / textattrs=(size=&TitleFontSize);
      entryfootnote halign=left "&footnote" /
        textattrs=(size=&FootnoteFontSize);
      entryfootnote halign=left "&footnote2" /
        textattrs=(size=&FootnoteFontSize);
      entryfootnote halign=left "&footnote3" /
        textattrs=(size=&FootnoteFontSize);
      layout lattice / columns=&NumVar rows=&NumVar rowgutter=5 columngutter=5
        rowdatarange=union columndatarange=union;

        /*--Set common row options--*/
        rowaxes;
          rowaxis / tickvalueattrs=(size=&TickValueFontSize) labelattrs=(size=&AxisLabelFontSize) 
            linearopts=(tickvaluesequence=(start=&AxisValueStart end=&AxisValueEnd increment=&AxisValueIncr) 
            tickvaluepriority=true);
          rowaxis / tickvalueattrs=(size=&TickValueFontSize) labelattrs=(size=&AxisLabelFontSize)
            linearopts=(tickvaluesequence=(start=&AxisValueStart end=&AxisValueEnd increment=&AxisValueIncr) 
            tickvaluepriority=true);
            %if &NumVar gt 2 %then %do;
              rowaxis / tickvalueattrs=(size=&TickValueFontSize) labelattrs=(size=&AxisLabelFontSize) 
                linearopts=(tickvaluesequence=(start=&AxisValueStart end=&AxisValueEnd increment=&AxisValueIncr) 
                tickvaluepriority=true);
            %end;
            %if &NumVar gt 3 %then %do;
              rowaxis / tickvalueattrs=(size=&TickValueFontSize) labelattrs=(size=&AxisLabelFontSize) 
                linearopts=(tickvaluesequence=(start=&AxisValueStart end=&AxisValueEnd increment=&AxisValueIncr) 
                tickvaluepriority=true);
            %end; 
        endrowaxes;

        /*--Set common column options--*/
        columnaxes;
          columnaxis / tickvalueattrs=(size=&TickValueFontSize) labelattrs=(size=&AxisLabelFontSize) 
            linearopts=(tickvaluesequence=(start=&AxisValueStart end=&AxisValueEnd increment=&AxisValueIncr)
            tickvaluepriority=true);
          columnaxis / tickvalueattrs=(size=&TickValueFontSize) labelattrs=(size=&AxisLabelFontSize) 
            linearopts=(tickvaluesequence=(start=&AxisValueStart end=&AxisValueEnd increment=&AxisValueIncr) 
            tickvaluepriority=true);
            %if &NumVar gt 2 %then %do;
              columnaxis / tickvalueattrs=(size=&TickValueFontSize) labelattrs=(size=&AxisLabelFontSize) 
                linearopts=(tickvaluesequence=(start=&AxisValueStart end=&AxisValueEnd increment=&AxisValueIncr) 
                tickvaluepriority=true);
            %end;
            %if &NumVar gt 3 %then %do;
              columnaxis / tickvalueattrs=(size=&TickValueFontSize) labelattrs=(size=&AxisLabelFontSize) 
                linearopts=(tickvaluesequence=(start=&AxisValueStart end=&AxisValueEnd increment=&AxisValueIncr) 
                tickvaluepriority=true);
            %end;
        endcolumnaxes;

        /*--Draw individual scatter plots in first row if needed--*/
        layout overlay;
          scatterplot y=&var2 x=&var1;
          %RefLines(x1=1, y1=1, x2=&CCL1, y2=&CCL2, pattern=Shortdash);
        endlayout;
        layout overlay; entry ''; endlayout;
        %if &NumVar gt 2 %then %do;
          layout overlay; entry ''; endlayout;
        %end;
        %if &NumVar gt 3 %then %do;
          layout overlay; entry ''; endlayout;
        %end;

        /*--Draw individual scatter plots in second row if needed--*/
        layout overlay;
          scatterplot y=&var3 x=&var1;
          %RefLines(x1=1, y1=1, x2=&CCL1, y2=&CCL3, pattern=Shortdash); 
        endlayout;
        layout overlay;
          scatterplot y=&var3 x=&var2;
          %RefLines(x1=1, y1=1, x2=&CCL2, y2=&CCL3, pattern=Shortdash); 
        endlayout;
        %if &NumVar gt 2 %then %do;
          layout overlay; entry ''; endlayout;
        %end;
        %if &NumVar gt 3 %then %do;
          layout overlay; entry ''; endlayout;
        %end;

        /*--Draw individual scatter plots in third row if needed--*/
        %if &NumVar gt 2 %then %do;
          layout overlay;
            scatterplot y=&var4 x=&var1;
            %RefLines(x1=1, y1=1, x2=&CCL1, y2=&CCL4, pattern=Shortdash);
          endlayout;
          layout overlay;
            scatterplot y=&var4 x=&var2;
            %RefLines(x1=1, y1=1, x2=&CCL2, y2=&CCL4, pattern=Shortdash);
          endlayout;
          layout overlay;
            scatterplot y=&var4 x=&var3;
            %RefLines(x1=1, y1=1, x2=&CCL3, y2=&CCL4, pattern=Shortdash);
          endlayout;
          %if &NumVar gt 3 %then %do;
            layout overlay; entry ''; endlayout;
          %end;
        %end;

        /*--Draw individual scatter plots in fourth row if needed--*/
        %if &NumVar gt 3 %then %do;
          layout overlay;
            scatterplot y=&var5 x=&var1;
            %RefLines(x1=1, y1=1, x2=&CCL1, y2=&CCL5, pattern=Shortdash);
          endlayout;
          layout overlay;
            scatterplot y=&var5 x=&var2;
            %RefLines(x1=1, y1=1, x2=&CCL2, y2=&CCL5, pattern=Shortdash);
          endlayout;
          layout overlay;
            scatterplot y=&var5 x=&var3;
            %RefLines(x1=1, y1=1, x2=&CCL3, y2=&CCL5, pattern=Shortdash);
          endlayout;
          layout overlay;
            scatterplot y=&var5 x=&var4;
            %RefLines(x1=1, y1=1, x2=&CCL4, y2=&CCL5, pattern=Shortdash);
          endlayout;
        %end;
      endlayout;
    endgraph;
  end;
run;

/*--Render the graph--*/
proc sgrender data=&data template=CompactMatrix_4_Out;
run;

%finished:
%mend CompactMatrixMacro;
/*------------------End of Macro Definition-------------------------*/

/*--Data--*/
data safety;
   label alat="ALAT (/ULN)";
   label biltot="BILTOT (/ULN)";
   label alkph="ALKPH (/ULN)";
   label asat="ASAT (/ULN)";
   label lab5="LAB5 (/ULN)";
   input alat biltot alkph asat drugnum @@;
   lab5=(alat+asat)/2;
   datalines;
1.50402    0.05708    0.33048    0.90276  1  0.52019    0.36690    0.07217    0.49515  1
0.61483    0.17867    0.57084    0.67013  2  0.66292    0.24336    0.25042    1.12487  1
1.08810    1.01795    0.34650    1.34532  2  0.79028    0.68118    0.32665    0.06345  1
0.52570    0.45411    0.28334    0.06357  1  1.01392    0.84606    0.28641    0.90854  2
1.13292    1.66524    0.34141    0.54517  1  0.39109    0.61881    0.76977    1.06455  2
0.29077    0.03953    1.02333    0.12085  2  0.08022    0.61256    0.63748    0.03751  1
0.28869    1.14711    0.85117    0.22888  1  0.68430    0.33865    1.27934    0.64995  1
0.28958    0.24271    0.88497    0.44784  1  0.59950    0.98547    0.82870    0.69982  1
1.14884    0.71048    0.52301    0.10196  1  0.74720    0.29196    0.09289    0.86770  2
0.04359    1.07114    0.51642    1.09350  2  0.79415    1.77495    0.68880    0.14667  1
0.21049    0.49933    0.04290    0.16268  2  0.30420    0.23086    0.80768    1.43123  1
0.82855    0.59293    0.69479    0.23548  1  0.92872    0.65368    0.27917    1.35438  2
0.64265    0.19259    0.39795    0.59636  2  0.19630    0.11172    0.02331    0.88034  1
0.27259    0.25195    0.10293    0.49052  1  0.92556    0.82656    0.78291    0.76708  1
0.64093    0.21803    0.20945    0.06697  2  1.86338    1.24297    0.64196    0.07128  1
0.46230    0.24378    1.29684    0.17389  1  1.34951    0.52357    0.25997    0.19045  2
0.21029    0.07059    0.36651    0.12194  1  0.42935    0.29198    1.39696    0.18104  1
0.62442    0.22078    0.11276    1.18317  1  1.40189    0.21334    0.10007    0.26606  2
0.17403    0.69906    0.11017    2.70367  2  0.10825    0.89657    0.18575    0.09142  2
0.73497    0.16258    0.18796    1.75182  1  0.50389    0.74195    1.00257    1.46249  1
1.59186    1.98800    0.31796    1.84198  1  1.70423    0.14395    0.33161    0.60179  2
1.46257    0.62399    0.25600    0.04913  2  0.96211    0.06294    0.91356    0.53554  1
0.75679    0.33871    0.02618    0.20742  2  0.18174    0.13500    0.27706    0.25103  1
0.16075    0.68592    0.57571    0.20039  2  1.42659    0.53351    1.42545    0.72487  1
1.91639    0.85802    1.26269    0.57197  2  0.79976    0.78239    0.04178    0.14514  2
1.81131    0.90045    0.57011    0.25534  2  1.23186    0.54773    0.37328    0.22021  2
0.66136    0.28402    0.05045    0.79116  1  0.07428    0.32438    0.21398    1.62037  2
0.98986    0.06453    1.14208    1.18013  1  0.68676    0.20856    0.25399    0.55969  2
0.06649    0.43363    0.90560    0.26845  2  0.76531    0.61245    0.73597    0.51179  2
0.33627    0.59912    0.71335    0.23930  2  0.71750    0.01282    1.29445    0.09027  1
0.77638    1.21813    1.52338    1.36050  2  0.19576    0.39795    0.45891    0.41354  2
0.08961    0.30520    0.39586    0.03269  2  0.06612    0.37675    0.05343    1.60441  1
0.62913    0.90338    0.89807    0.03400  1  0.49409    0.07936    0.20737    0.41714  2
0.75204    0.45698    0.58023    0.50012  2  0.27998    0.27589    0.14848    0.07016  1
0.56094    0.69074    0.28121    0.22961  1  0.30435    1.02185    1.27321    0.47303  1
1.10021    0.17047    0.33113    0.30318  2  0.02911    0.26894    0.15328    0.79870  2
1.75579    0.13909    1.18164    0.75928  2  1.40748    0.12699    1.02493    0.50448  2
0.28524    0.47159    1.60690    0.20059  2  0.32504    0.32206    0.16286    0.91272  1
0.35609    0.91710    0.12535    0.13337  2  1.51385    0.65495    1.21880    1.10917  1
0.03512    0.21372    0.51937    0.81195  2  1.16905    0.12493    0.11143    0.77166  2
0.10314    0.56135    0.05451    0.30021  1  2.30313    0.13978    0.63976    0.11976  2
0.26900    0.77324    0.55505    3.81230  2  1.08605    0.31617    0.91117    1.53117  1
1.05603    0.70337    0.49963    0.75516  1  0.29395    0.78740    0.28114    1.07866  1
2.28700    1.70266    0.11234    0.51744  1  0.13196    0.16789    0.64827    0.52155  2
0.03618    0.35690    0.40794    2.02275  1  0.82262    0.03359    0.46697    0.42283  2
1.47206    0.92371    0.05976    0.18233  2  0.46250    0.57460    0.22474    0.48443  1
0.54458    0.28868    1.86455    0.57534  2  0.39313    0.04371    0.57599    0.09348  1
0.07420    0.48951    0.25404    0.41949  1  2.03402    0.23141    1.25288    0.24619  1
0.44685    0.26911    0.31767    1.13628  2  0.13956    0.38036    0.54122    0.14997  1
1.16847    1.66600    3.11100    0.52793  2  0.10580    0.43407    0.80791    0.15014  1
;
run;

/*--Compact 4x4 Matrix Graph--*/
ods listing style=htmlblue gpath=&graphs image_dpi=&dpi;
ods graphics / reset noscale width=&w height=&h imagename='LFT_Matrix_4x4';
%CompactMatrixMacro(data=safety, var1=asat, var2=alat, var3=alkph, var4=biltot,
         CCL1=3, CCL2=3, CCL3=2, CCL4=2, 
         title=Matrix Display of Maximum LFT Values, 
         footnote=For ASAT and ALAT the clinical concern level (CCL) is 3.0 ULN,
         footnote2=For BILTOT and ALKPH the clinical concern level (CCL) is 2.0 ULN,
         footnote3=Where ULN is the upper level of normal range,
         titlefontsize=12, footnotefontsize=9, axisvalueincr=1);