SlideShare a Scribd company logo
IS THE LEGEND IN YOUR
SAS/GRAPH® OUTPUT ST  ILL
TELLING THE RIGHT STORY?

        ALICE M. CHENG
        OCTOBER13, 2011
OBJECTIVES

 To explore both traditional and the latest approaches
  to ensure Legend Consistency.

 This paper is meant to be a sequel to the SUGI 29 paper:

        Is the legend in your SAS/Graph®
        output Telling the right story?
            Justina M. Flavin, Art Carpenter




                                                             2
AGENDA

 The Nature of SGPLOT Procedure.

  How are Line Attributes Assigned?

 Re-visit the Line Inconsistency Problem
  by means of SGPLOT Procedure.

 5 Solutions to Resolve Line Inconsistency Issues.

 The SGPANEL Procedure
  (as a Special Case of SGPLOT Procedure).




                                                      3
INTRODUCTION

 Line Attributes (line color, symbol and style).


      Placebo


      Drug A


      Drug B


      Drug C



   It is critical that line attributes are CONSISTENT.
                                                         4
THE NATURE OF SGPLOT

(HOW ARE LINES ATTRIBUTES ASSIGNED?)




                                       5
Treatment
                                                       Order based
                                                       on Input Data
                                                       Order.




                                                                    6
Figure 1A: Average Scores of 4 Treatments are displayed according
           to input data order.
INPUT DATASET
data DRUG;
  input TRT & $7. MONTH : 2. SCORE : 3. @@;
  label TRT=‘Treatment:’
        MONTH=‘Month’
        SCORE=‘Average Score’;
Datalines;
Placebo 1 10 Placebo 2 15 Placebo 3 18 Placebo 4 20 Placebo 5 22
Drug A 1 30 Drug A 2 40 Drug A 3 60 Drug A 4 85 Drug A 5 100
Drug B 1 20 Drug B 2 30 Drug B 3 45 Drug B 4 70 Drug B 5 90
Drug C 1 25 Drug C 2 30 Drug C 3 35 Drug C 4 60 Drug C 5 85
;
run;




   Note: Based on input dataset DRUG,
         Order of Treatments is: Placebo, Drug A, Drug B, Drug C.
                                                                    7
DEFINE STYLE
proc template;
  define style STYLES.MYSTYLES;
   parent=STYLES.DEFAULT;
    *--- Re-define Style for Line Attributes. ---*;
    style GraphData1 from GraphData1 / linestyle=1 contrastcolor=red
          markersymbol=‘circle’; * Line Attributes for 1st Treatment. ;
    style GraphData2 from GraphData2 / linestyle=2 contrastcolor=blue
          markersymbol=‘square’; * Line Attributes for 2nd Treatment. ;
    style GraphData3 from GraphData3 / linestyle=3 contrastcolor=green
          markersymbol=‘diamond’; * Line Attributes for 3rd Treatment. ;
    style GraphData4 from GraphData4 / linestyle=4 contrastcolor=orange
          markersymbol=‘circlefilled’; * Line Attributes for 4th Treatment. ;
     *--- Re-define other styles to make sure the graph is easier to read. ---*;
     class GraphFonts / ‘GraphLabelFont’=(“Arial”, 18pt, bold)
                         ‘GraphValueFont’=(“Arial”, 15pt, bold)
                         ‘GraphTitleFont’=(“Arial”, 25pt, bold);
     style graphbackground from graphbackground / color = _undef_;
   end;
run;

Note: The k-th treatment in the input dataset takes on the k-th color here.        8
For instance, the first treatment (Placebo) takes on the RED color.
USE SGPLOT TO GENERATE FIGURE

 ods listing style=STYLES.MYSTYLE;
 title ‘Score Over Time by Treatment’;
 proc sgplot data=DRUG;
    series y=SCORE x=MONTH / group=TRT markers;
    keylegend / noborder title=‘Treatment’;
 run;




        Use the style STYLES.MYSTYLE.
        Assign TRT as the GROUP variable.




                                                  9
PROC SGPLOT VS PROC GPLOT

                              SGPLOT                   GPLOT


    Default Order         Data Order               Internal Value
    of Group
    (TRT) Variable
    Line                 Style Statement in           Symboln
    Attributes           PROC TEMPLATE               Statement


So if you want to present the values based on Internal Value of the Group
Variable in PROC SGPLOT (like in GPLOT), prior to SAS 9.3, you have to
sort by the Group (TRT) variable.



                                                                            10
Or in SAS Version 9.3, use …


 proc sgplot data = DRUG;
   series y=SCORE x=MONTH / GROUP=TRT
                            GROUPORDER=ascending
                            markers;
 run;



GROUP=variable and GROUPORDER=ascending/descending/data options
in the SERIES statement specify:

         the order of the values in the GROUP variable

based on which the line attributes have been assigned to the groups.

                                                                       11
Now based on
                                                            the ascending
                                                            order of the
                                                            value of TRT.




Figure 1B: With GROUP=TRT and GROUPORDER=ASCENDING,
the order of the treatments in the legend and the line attributes
                                                                      12
have been changed.
THE PROBLEM

(Line Inconsistency when using SGPLOT.)




                                          13
LINE ATTRIBUTES

 Line Attributes (line color, symbol and style).


      Drug A


      Drug B


      Drug C

      Placebo


   It is critical that line attributes are CONSISTENT.


                                                         14
WHAT IF DRUG B IS NO LONGER IN A STUDY?
                                    SGPLOT
          Drop Drug B   We Want
                                    (Default)

Drug A

Drug B


Drug C


Placebo


 THE LINE ATTRIBUTES ARE NO LONGER CONSISTENT.


                                                 15
Error!!!
                                                          Inconsistency
                                                          In line attribute.
                                                          Drug C should
                                                          GREEN and
                                                          Placebo should
                                                          be ORANGE!




Figure 2: The same line inconsistency issues in the GPLOT
procedure now re-appears in the output for SGPLOT procedure               16
when Drug B is excluded.
THE FIGURE WE WANT …




                                                                    17
 Note: The lines in the legend are consistent with the lines when
       all 4 treatments are available.
5 SOLUTIONS TO RESOLVE
LINE INCONSISTENCY ISSUES




                            18
SOLUTION # 1

USE DUMMY DATA




                 19
Solution # 1. Use Dummy Data



  Create a dummy dataset with a single observation
   for each treatment group.

 In this dummy dataset, only the Group variable has
  non-missing values.

  Add this dummy dataset to your original dataset.




                                                       20
Solution # 1. Use Dummy Data
*- Create a DUMMY dataset so that all treatment groups are represented. -*;
 data DUMMY;
   length TRT $7.;
   TRT=‘Drug A’;     MONTH= . ;   SCORE= . ; output;
   TRT=‘Drug B’;     MONTH= . ;   SCORE= . ; output;
   TRT=‘Drug C’;     MONTH= . ;   SCORE =. ; output;
   TRT=‘Placebo’;    MONTH= . ;   SCORE =.; output;
 run;
 *- Add DUMMY dataset to the original DRUG dataset without Drug B. -*;
 data DRUG_WT_DUMMY;
                                          Note: DUMMY data must come
   set DUMMY
                                          before DRUG data to retain the
       DRUG (where=(TRT ne ‘Drug B’) );
                                          right order.
 run;
  *- Generate Figure 3A. -*;
  ods listing style=STYLES.MYSTYLE;
  proc sgplot data=DRUG_WT_DUMMY;
    series y=SCORE x=MONTH / group=TRT markers;
    keylegend / noborder title=‘Treatment’;
  run;                                                                        21
Solution # 1. Use Dummy Data




                                                               Since Drug B
                                                               is not supposed
                                                               to be in this
                                                               figure.
                                                               Drug B should
                                                               NOT be in the
                                                               legend!!!




                                                                             22
Figure 3A: The Add Dummy Data Approach ensures line consistency,
However, the excluded treatment group Drug B remains in the legend.
SOLUTION # 2

RE-MAP LINE ATTRIBUTES




                         23
Solution # 2. Re-Map Line Attributes


 Create a LOOKUP dataset with data for every possible
    GROUP variable value and its line attributes.

 Get the data from LOOKUP dataset for the GROUP
   variable values and their line attributes based on current
   source database.

  Create a new template by Re-defining the
     Style GraphDatan statements.

  Apply the newly defined Style to PROC SGPLOT.


                                                                24
Solution # 2. RE-MAP LINE ATTRIBUTE


 *- Establish a LOOKUP dictionary for line attribute for each drug. -*;
   data LOOKUP;
    input ID & $7. LINESTYLE : 3. COLOR : $6. SYMBOL : $12.;
    cards;
    Drug A 1 red circle
    Drug B 2 blue square
    Drug C 3 green diamond
    Placebo 4 orange circlefilled
    ;
   run;




                                                                          25
Solution # 2. RE-MAP LINE ATTRIBUTE
*- Define LINEATTR macro to create Style Template with line attributes. -*;
%macro lineattr ( indata =                       /* Enter Input Data Set Name      */
               , lookup=LOOKUP                 /* Enter LOOKUP Dataset            */
               , idvar=ID                      /* ID variable in LOOKUP Data Set. */
               , groupvar=TRT                   /* Enter Group Variable.          */
               , style=STYLES.MYSTYLE2 /* Enter Style name to be output.           */
               , parent_style=STYLES.MYSTYLE /* Enter Parent Style. */
                 )/ des=‘To create line attributes in Style Template’;
%local I;

%*- Get line attribute for treatment groups from LOOKUP.                        -*%;
%*- Note: only line attributes for treatment groups in the dataset specified in -*%;
%*- the dataset specified in &indata will be kept.                              -*%;
proc sql noprint;
  create table LINEATTR as
     select distinct L.*, D.&GROUPVAR
       from &indata D
                left join
             &LOOKUP L
              on D.&GROUPVAR=L.&IDVAR
                  order by D.&GROUPVAR;                                                 26
quit;
Solution # 2. RE-MAP LINE ATTRIBUTE
%*- Assign value for the line style, colors and symbol of each treatment. -*%;
data null;
  set LINEATTR;
  call symput (‘LINESTYLE’ || strip(_n_, 3.)), LINESTYLE);
  call symput (‘COLOR’ || strip ( put (_n_, 3.)), COLOR);
  call symput (‘SYMBOL’|| strip(put (_n_, 3.)), strip(SYMBOL) );
run;

%*- Redefine your line attributes in a new style. -*%;
proc template;
  define style &STYLE;
    parent=&parent_style;
    %do i=1 %to &sqlobs;
        style GraphData&i from GraphData&i / linestyle=&&LINESTYLE&i
              contrastcolor=&&color&I markersymbol=&&symbol&i;
    %end;
   end;
Run;
%mend lineattr;


                                                                                 27
Solution # 2. RE-MAP LINE ATTRIBUTE

*- Create a dataset based on DRUG, excluding TRT B. -*;
data DRUG_noB;
  set DRUG (where=(TRT ne ‘Drug B’));
run;

*- Invoke %lineattr to create STYLES.MYSTYLES2 with the correct line styles. -*;

%lineattr(indata=DRUG_noB,
          style=STYLES.MYSTYLES2);

ods listing style=STYLES.MYSTYLES2;
Title h=20pt ‘Score Over Time by Treatment’;
proc sgplot data=DRUG_noB;
  series y=SCORE x=MONTH / group=TRT markers;
  keylegend / noborder title=‘Treatment: ‘;
run;




                                                                               28
This is the
                                                                           figure we
                                                                           want!




Figure 3B: 3 remaining treatments are represented by lines consistent in             29
appearance as those seen in Figure 1B. Legend reflects only the lines
in the figure.
SOLUTION # 3

RE-CODE INTERNAL VALUES
   OF GROUP VARIABLE




                          30
WHAT IF DRUG B IS NO LONGER IN A STUDY?
                                              SGPLOT
             Drop Drug B       We Want
                                              (Default)

 Drug A

 Drug B


 Drug C


Placebo


NOTE: Line attributes before the deleted group, namely DRUG A,
      remain intact.

                                                            31
WHAT IF PLACEBO IS NOT IN A STUDY?
                                                  SGPLOT
                Drop Placebo      We Want
                                                  (Default)

   Drug A

   Drug B


   Drug C


  Placebo



NOTE: Line attributes are consistent.

        Line attributes before the deleted group remain intact.
                                                                  32
Solution # 3. RE-CODE INTERNAL VALUES OF GROUP VARIABLE




    So if one knows ahead of the treatments that are going to be
     dropped, one can put these treatments to be dropped last,
     in terms of its internal value.


  The  line attributes for the remaining treatment groups will
     remain intact.




                                                                    33
Solution # 3. RE-CODE INTERNAL VALUES OF GROUP VARIABLE
   *- Define formats for re-coding group variable, TRT. -*;
   proc format;
     invalue INTRTF ‘Drug A’ = 1
                      ‘Drug B’ = 4
                      ‘Drug C’= 2
                      ‘Placebo’=3;
     value TRTF 1= ‘Drug A’
                   2=‘Drug C’               Note that Drug B is now
                   3=‘Placebo’              assigned to the largest value!
                   4=‘Drug B’;
   run;
   *- Re-coded the value from TRT to TRT2 so that treatment groups to be -*;
   *- dropped have higher internal values and will be listed last.           -*;
   data DRUG_RECODED;
      set DRUG (where=(TRT ne ‘Drug b’) );
      TRT2=input(TRT, intrf.);
      label TRT2=‘Treatment: ‘;
      format TRT2 TRTF.; run;
   *- Sort the data based on the internal value of the re-coded variable -*;
   *- of TRT2. -*;
   proc sort data=DRUG_RECODED;
      by TRT2;                                                                     34
   run;
Solution # 3. RE-CODE INTERNAL VALUES OF GROUP VARIABLE
 *- Re-order the line attributes to match internal values of group variable, TRT2;
 proc template;
    define style STYLES.MYSTYLE3;
      parent=STYLES.MYSTYLE;
      style GraphData1 from GraphData1 / linestyle=1 contrastcolor=RED
          markersymbol=‘circle’;
    style GraphData2 from GraphData2 / linestyle=3 contrastcolor=GREEN
          markersymbol=‘diamond’;
    style GraphData3 from GraphData3 / linestyle=4 contrastcolor=ORANGE
          markersymbol=‘circlefilled’;
    style GraphData4 from GraphData4 / linestyle=2 contrastcolor=BLUE
          markersymbol=‘square’;
    end;
 Run;
                                       Note: line attributes for Drug B
                                      is now the last in the list.
 *- Generate Figure 3B that excludes Drug B with Re-coded variable, TRT2 -*;
 ods listing style=STYLES.MYSTYLES3;
   title ‘Score Over Time by Treatment’;
   proc sgplot data=DRUG_RECORDED;
       series y=SCORE x=MONTH / group=TRT2 markers;
       keylegend/noborder title=‘Treatment: ‘;                                       35
 Run;
SOLUTION # 4
     USE INDEX OPTION IN
GRAPH TEMPLATE LANGUAGE (GTL)




                                36
PROC SGPLOT vs Graph Template Language (GTL)


        PROC SGPLOT                GTL
     Single Cell Plot      Multiple Cell Plot
     Quality Graphics     Higher Quality Graphics
     Some Customization   More Customization
     Quick and Easy to    Require Significant Time
     Learn and Use        and Effort to Learn




                                                     37
Use of Index Options in GTL Can Ensure Line Consistency.
 What if you have yet to master GTL?

   If you have SAS 9.3, you can use SG Attribute Map (Solution #5).

   If not and if you only need a simple plot that can be produced by the SG
    procedure, you can use TMPLST options to get the code to create the
    template and then render that template.

Example:

proc sgplot data=DRUG
     tmplst=“c:alicewuss_2011_graphline_plot.sas”;
  series y=SCORE x=MONTH / group=TRT markers;
  keylegend/noborder title=‘Treatment: ‘;
run;


                                                                          38
Solution # 4. USING INDEX IN GTL
*- Create a variable IDVAL to associate the group variables with -*;
*- line attributes defined in STYLES.MYSTYLE.                        -*;
data DRUG_IDVAL;
  set DRUG (where=(TRT NE ‘Drug B’) );
  if TRT=‘Drug A’ then IDVAL=1;
     else if TRT=‘Drug B’ then IDVAL=2;
     else if TRT=‘Drug C’ then IDVAL= 3;
     else if TRT=‘Placebo’ then IDVAL=4;
run;
*- Template SGPLOT was obtained from TMPLOUT options in PROC SGPLOT.-*;
*- INDEX options in SERIESPLOT statement has been added manually.                  -*;
proc template;
  define statgraph SGPLOT;
  begingraph;
  EntryTitle “Score Over Time by Treatment’/ textattrs=(size=2pct);
  layout overlay;
      seriesplot x=MONTH y=SCORE /
        primary=true group=TRT index=IDVAL display=(markers)
        LegendLabel=“Average Score” Name=“SERIES”;
      DiscreteLegend “Series” / Location=Outside Title=“Treatment: “ Border=false;
   endlayout;
                                                                                         39
   endgraph;                           Add Manually.
end; run;
Solution # 4. USING INDEX IN GTL




 *- Use PROC SGRENDER to render the graph from the stored graphics -*;
 * Template SGPLOT.                                                 -*;

  ods listing style=STYLES.MYSTYLE;
  proc sgrender data=DRUG_IDVAL template=SGPLOT;
  run;




                                                                          40
SOLUTION # 5
USE OF SG ATTRIBUTE MAP
   (Available in SAS Version 9.3)




                                    41
Solution # 5. USING SG Attribute Map Approach

 *- Create Attribute Map Data Set named MYATTRMAP. ---*;
 data MYATTRMAP;
    retain ID “MYID”;
    input VALUE & $7. LINESTYLE : 3. LINECOLOR : $6
          MARKERSYMBOL : $12 MARKCOLOR : $6.;
 cards;
 Drug A 1 red          circle   red
 Drug B 2 blue         square blue
 Drug C 3 green diamond green
 Placebo 4 orange circlefilled orange
 ; run;

 *- Reference to MYATTRMAP to define the line attributes. -*;
 ods listing;
 title ‘Score Over Time by Treatment’;
 proc sgplot data=DRUG dattrmap=MYATTRMAP;
    series y=SCORE X=MONTH / group=TRT attrid=MYID
      marker;                                                   42
    keylegend / noborder title=“Treatment: “; run;
THE SGPANEL PROCEDURE




                        43
A Panel of Graph Cells Produced by PROC SGPANEL


                                                     PANELBY variables
                                                     (BMI, SUBJID) controls
                                                     the cell order.




                                                                          44

Figure 4A: Lines are NOT consistent with the desirable line attributes.
THE SGPANEL PROCEDURE
Code for Figure 4A

ods listing style=STYLES.MYSTYLE;
title h=20pt ‘HbA1c (%) by Month’;
proc sgpanel data=HBA1C;
   panelby BMI SUBJID / layout=panel columns=3 colheader=top
     rowheaderpos=right uniscale=row start=topleft spacing=5;
   series x=MONTH y=HBA1C / group=TRT name=‘HBA1C’
     lineattrs=(pattern=solid thickness=3) markers;
   keylegend ‘HBA2C’ / noborder position=bottom title=“Treatment: “;
   colaxis value=(0 3 6 9 12) label=‘Month’;
   rowaxis label=‘HbA1c (%)’;
run;

 Unlike SGPLOT, in SGPANEL, the default order is controlled by
  the order of PANELBY variables and then the order of GROUP
  variable within the same panel.
                                                                          45
 Here, we can think of each cell as having 3 missing treatment groups.
A Panel of Graph Cells Produced by PROC SGPANEL




                                                                           46

     Figure 4B: Lines are consistent with the desirable line attributes.
THE SGPANEL PROCEDURE
Code for Figure 4B (Using Index Options in GTL)

ods listing style=STYLES.MYSTYLE;
title h=20pt ‘HbA1c (%) by Month’;
proc sgpanel data=HBA1C tmplout=“c:wuss_2011Figure4B.sas” ;
   panelby BMI SUBJID / layout=panel columns=3 colheader=top
     rowheaderpos=right uniscale=row start=topleft spacing=5;
   series x=MONTH y=HBA1C / group=TRT name=‘HBA1C’
     lineattrs=(pattern=solid thickness=3) markers;
   keylegend ‘HBA2C’ / noborder position=bottom title=“Treatment: “;
   colaxis value=(0 3 6 9 12) label=‘Month’;
   rowaxis label=‘HbA1c (%)’;
run;




                                                                       47
Code for Figure 4B

*- Define a template name GPANEL -*;
proc template;
  define statgraph SGPANEL;
  … SAS codes …;
  begingraph / …;
  EntryTitle “HbA1c (%) by Month” / textattrs=(size=20pt);
  layout datapanel classvars= (BMI SUBJID) / …;
  … SAS codes …;                       Add Manually.
    layout prototype / __SGPROC;
    SeriesPlot x=MONTH y=HBA1C / primary=true display=(markers)
    Group=TRT INDEX=INDVAL Lineattrs=(Pattern=1 Thickness=3)
       LegendLabel=“HbA1c” Name=“HBA1C”;
    endlayout;
   endlayout;
   DiscreteLegend “HBA1c” / Title=“Treatment: “ Border=false;
 endlayout; endgraph; end; run;

ods listing style=STYLES.MYSTYLE;
proc sgrender data=HBA1C template=SGPANEL;                        48
run;
ACKNOWLEDGEMENT

 Art Carpenter, Caloxy

 Shawn Hopkin, Seattle Genetics

 Lelia McConnell, SAS Technical Support
 Susan Morrison, SAS Technical Support

 Marcia Surratt, SAS Technical Support




                                           49
The END
          50

More Related Content

Viewers also liked

SAS Techniques (WUSS 2011)
SAS Techniques (WUSS 2011)SAS Techniques (WUSS 2011)
SAS Techniques (WUSS 2011)
alice_m_cheng
 
How to Speed Up Your Validation Process Without Really Trying?
How to Speed Up Your Validation Process Without Really Trying?How to Speed Up Your Validation Process Without Really Trying?
How to Speed Up Your Validation Process Without Really Trying?
alice_m_cheng
 
Duration Calculation (SUGI 31)
Duration Calculation (SUGI 31)Duration Calculation (SUGI 31)
Duration Calculation (SUGI 31)
alice_m_cheng
 
CDISC journey in solid tumor using recist 1.1 (Paper)
CDISC journey in solid tumor using recist 1.1 (Paper)CDISC journey in solid tumor using recist 1.1 (Paper)
CDISC journey in solid tumor using recist 1.1 (Paper)
Kevin Lee
 
Sas demo
Sas demoSas demo
Base SAS Full Sample Paper
Base SAS Full Sample Paper Base SAS Full Sample Paper
Base SAS Full Sample Paper
Jimmy Rana
 
Understanding SAS Data Step Processing
Understanding SAS Data Step ProcessingUnderstanding SAS Data Step Processing
Understanding SAS Data Step Processing
guest2160992
 

Viewers also liked (7)

SAS Techniques (WUSS 2011)
SAS Techniques (WUSS 2011)SAS Techniques (WUSS 2011)
SAS Techniques (WUSS 2011)
 
How to Speed Up Your Validation Process Without Really Trying?
How to Speed Up Your Validation Process Without Really Trying?How to Speed Up Your Validation Process Without Really Trying?
How to Speed Up Your Validation Process Without Really Trying?
 
Duration Calculation (SUGI 31)
Duration Calculation (SUGI 31)Duration Calculation (SUGI 31)
Duration Calculation (SUGI 31)
 
CDISC journey in solid tumor using recist 1.1 (Paper)
CDISC journey in solid tumor using recist 1.1 (Paper)CDISC journey in solid tumor using recist 1.1 (Paper)
CDISC journey in solid tumor using recist 1.1 (Paper)
 
Sas demo
Sas demoSas demo
Sas demo
 
Base SAS Full Sample Paper
Base SAS Full Sample Paper Base SAS Full Sample Paper
Base SAS Full Sample Paper
 
Understanding SAS Data Step Processing
Understanding SAS Data Step ProcessingUnderstanding SAS Data Step Processing
Understanding SAS Data Step Processing
 

Recently uploaded

Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
Rohit Gautam
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website
Pixlogix Infotech
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Vladimir Iglovikov, Ph.D.
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Speck&Tech
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
James Anderson
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 

Recently uploaded (20)

Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 

Legend Consistency, SAS (WUSS 2011)

  • 1. IS THE LEGEND IN YOUR SAS/GRAPH® OUTPUT ST ILL TELLING THE RIGHT STORY? ALICE M. CHENG OCTOBER13, 2011
  • 2. OBJECTIVES  To explore both traditional and the latest approaches to ensure Legend Consistency.  This paper is meant to be a sequel to the SUGI 29 paper: Is the legend in your SAS/Graph® output Telling the right story? Justina M. Flavin, Art Carpenter 2
  • 3. AGENDA  The Nature of SGPLOT Procedure. How are Line Attributes Assigned?  Re-visit the Line Inconsistency Problem by means of SGPLOT Procedure.  5 Solutions to Resolve Line Inconsistency Issues.  The SGPANEL Procedure (as a Special Case of SGPLOT Procedure). 3
  • 4. INTRODUCTION  Line Attributes (line color, symbol and style). Placebo Drug A Drug B Drug C It is critical that line attributes are CONSISTENT. 4
  • 5. THE NATURE OF SGPLOT (HOW ARE LINES ATTRIBUTES ASSIGNED?) 5
  • 6. Treatment Order based on Input Data Order. 6 Figure 1A: Average Scores of 4 Treatments are displayed according to input data order.
  • 7. INPUT DATASET data DRUG; input TRT & $7. MONTH : 2. SCORE : 3. @@; label TRT=‘Treatment:’ MONTH=‘Month’ SCORE=‘Average Score’; Datalines; Placebo 1 10 Placebo 2 15 Placebo 3 18 Placebo 4 20 Placebo 5 22 Drug A 1 30 Drug A 2 40 Drug A 3 60 Drug A 4 85 Drug A 5 100 Drug B 1 20 Drug B 2 30 Drug B 3 45 Drug B 4 70 Drug B 5 90 Drug C 1 25 Drug C 2 30 Drug C 3 35 Drug C 4 60 Drug C 5 85 ; run; Note: Based on input dataset DRUG, Order of Treatments is: Placebo, Drug A, Drug B, Drug C. 7
  • 8. DEFINE STYLE proc template; define style STYLES.MYSTYLES; parent=STYLES.DEFAULT; *--- Re-define Style for Line Attributes. ---*; style GraphData1 from GraphData1 / linestyle=1 contrastcolor=red markersymbol=‘circle’; * Line Attributes for 1st Treatment. ; style GraphData2 from GraphData2 / linestyle=2 contrastcolor=blue markersymbol=‘square’; * Line Attributes for 2nd Treatment. ; style GraphData3 from GraphData3 / linestyle=3 contrastcolor=green markersymbol=‘diamond’; * Line Attributes for 3rd Treatment. ; style GraphData4 from GraphData4 / linestyle=4 contrastcolor=orange markersymbol=‘circlefilled’; * Line Attributes for 4th Treatment. ; *--- Re-define other styles to make sure the graph is easier to read. ---*; class GraphFonts / ‘GraphLabelFont’=(“Arial”, 18pt, bold) ‘GraphValueFont’=(“Arial”, 15pt, bold) ‘GraphTitleFont’=(“Arial”, 25pt, bold); style graphbackground from graphbackground / color = _undef_; end; run; Note: The k-th treatment in the input dataset takes on the k-th color here. 8 For instance, the first treatment (Placebo) takes on the RED color.
  • 9. USE SGPLOT TO GENERATE FIGURE ods listing style=STYLES.MYSTYLE; title ‘Score Over Time by Treatment’; proc sgplot data=DRUG; series y=SCORE x=MONTH / group=TRT markers; keylegend / noborder title=‘Treatment’; run;  Use the style STYLES.MYSTYLE.  Assign TRT as the GROUP variable. 9
  • 10. PROC SGPLOT VS PROC GPLOT SGPLOT GPLOT Default Order Data Order Internal Value of Group (TRT) Variable Line Style Statement in Symboln Attributes PROC TEMPLATE Statement So if you want to present the values based on Internal Value of the Group Variable in PROC SGPLOT (like in GPLOT), prior to SAS 9.3, you have to sort by the Group (TRT) variable. 10
  • 11. Or in SAS Version 9.3, use … proc sgplot data = DRUG; series y=SCORE x=MONTH / GROUP=TRT GROUPORDER=ascending markers; run; GROUP=variable and GROUPORDER=ascending/descending/data options in the SERIES statement specify: the order of the values in the GROUP variable based on which the line attributes have been assigned to the groups. 11
  • 12. Now based on the ascending order of the value of TRT. Figure 1B: With GROUP=TRT and GROUPORDER=ASCENDING, the order of the treatments in the legend and the line attributes 12 have been changed.
  • 13. THE PROBLEM (Line Inconsistency when using SGPLOT.) 13
  • 14. LINE ATTRIBUTES  Line Attributes (line color, symbol and style). Drug A Drug B Drug C Placebo It is critical that line attributes are CONSISTENT. 14
  • 15. WHAT IF DRUG B IS NO LONGER IN A STUDY? SGPLOT Drop Drug B We Want (Default) Drug A Drug B Drug C Placebo THE LINE ATTRIBUTES ARE NO LONGER CONSISTENT. 15
  • 16. Error!!! Inconsistency In line attribute. Drug C should GREEN and Placebo should be ORANGE! Figure 2: The same line inconsistency issues in the GPLOT procedure now re-appears in the output for SGPLOT procedure 16 when Drug B is excluded.
  • 17. THE FIGURE WE WANT … 17 Note: The lines in the legend are consistent with the lines when all 4 treatments are available.
  • 18. 5 SOLUTIONS TO RESOLVE LINE INCONSISTENCY ISSUES 18
  • 19. SOLUTION # 1 USE DUMMY DATA 19
  • 20. Solution # 1. Use Dummy Data  Create a dummy dataset with a single observation for each treatment group.  In this dummy dataset, only the Group variable has non-missing values.  Add this dummy dataset to your original dataset. 20
  • 21. Solution # 1. Use Dummy Data *- Create a DUMMY dataset so that all treatment groups are represented. -*; data DUMMY; length TRT $7.; TRT=‘Drug A’; MONTH= . ; SCORE= . ; output; TRT=‘Drug B’; MONTH= . ; SCORE= . ; output; TRT=‘Drug C’; MONTH= . ; SCORE =. ; output; TRT=‘Placebo’; MONTH= . ; SCORE =.; output; run; *- Add DUMMY dataset to the original DRUG dataset without Drug B. -*; data DRUG_WT_DUMMY; Note: DUMMY data must come set DUMMY before DRUG data to retain the DRUG (where=(TRT ne ‘Drug B’) ); right order. run; *- Generate Figure 3A. -*; ods listing style=STYLES.MYSTYLE; proc sgplot data=DRUG_WT_DUMMY; series y=SCORE x=MONTH / group=TRT markers; keylegend / noborder title=‘Treatment’; run; 21
  • 22. Solution # 1. Use Dummy Data Since Drug B is not supposed to be in this figure. Drug B should NOT be in the legend!!! 22 Figure 3A: The Add Dummy Data Approach ensures line consistency, However, the excluded treatment group Drug B remains in the legend.
  • 23. SOLUTION # 2 RE-MAP LINE ATTRIBUTES 23
  • 24. Solution # 2. Re-Map Line Attributes  Create a LOOKUP dataset with data for every possible GROUP variable value and its line attributes.  Get the data from LOOKUP dataset for the GROUP variable values and their line attributes based on current source database.  Create a new template by Re-defining the Style GraphDatan statements.  Apply the newly defined Style to PROC SGPLOT. 24
  • 25. Solution # 2. RE-MAP LINE ATTRIBUTE *- Establish a LOOKUP dictionary for line attribute for each drug. -*; data LOOKUP; input ID & $7. LINESTYLE : 3. COLOR : $6. SYMBOL : $12.; cards; Drug A 1 red circle Drug B 2 blue square Drug C 3 green diamond Placebo 4 orange circlefilled ; run; 25
  • 26. Solution # 2. RE-MAP LINE ATTRIBUTE *- Define LINEATTR macro to create Style Template with line attributes. -*; %macro lineattr ( indata = /* Enter Input Data Set Name */ , lookup=LOOKUP /* Enter LOOKUP Dataset */ , idvar=ID /* ID variable in LOOKUP Data Set. */ , groupvar=TRT /* Enter Group Variable. */ , style=STYLES.MYSTYLE2 /* Enter Style name to be output. */ , parent_style=STYLES.MYSTYLE /* Enter Parent Style. */ )/ des=‘To create line attributes in Style Template’; %local I; %*- Get line attribute for treatment groups from LOOKUP. -*%; %*- Note: only line attributes for treatment groups in the dataset specified in -*%; %*- the dataset specified in &indata will be kept. -*%; proc sql noprint; create table LINEATTR as select distinct L.*, D.&GROUPVAR from &indata D left join &LOOKUP L on D.&GROUPVAR=L.&IDVAR order by D.&GROUPVAR; 26 quit;
  • 27. Solution # 2. RE-MAP LINE ATTRIBUTE %*- Assign value for the line style, colors and symbol of each treatment. -*%; data null; set LINEATTR; call symput (‘LINESTYLE’ || strip(_n_, 3.)), LINESTYLE); call symput (‘COLOR’ || strip ( put (_n_, 3.)), COLOR); call symput (‘SYMBOL’|| strip(put (_n_, 3.)), strip(SYMBOL) ); run; %*- Redefine your line attributes in a new style. -*%; proc template; define style &STYLE; parent=&parent_style; %do i=1 %to &sqlobs; style GraphData&i from GraphData&i / linestyle=&&LINESTYLE&i contrastcolor=&&color&I markersymbol=&&symbol&i; %end; end; Run; %mend lineattr; 27
  • 28. Solution # 2. RE-MAP LINE ATTRIBUTE *- Create a dataset based on DRUG, excluding TRT B. -*; data DRUG_noB; set DRUG (where=(TRT ne ‘Drug B’)); run; *- Invoke %lineattr to create STYLES.MYSTYLES2 with the correct line styles. -*; %lineattr(indata=DRUG_noB, style=STYLES.MYSTYLES2); ods listing style=STYLES.MYSTYLES2; Title h=20pt ‘Score Over Time by Treatment’; proc sgplot data=DRUG_noB; series y=SCORE x=MONTH / group=TRT markers; keylegend / noborder title=‘Treatment: ‘; run; 28
  • 29. This is the figure we want! Figure 3B: 3 remaining treatments are represented by lines consistent in 29 appearance as those seen in Figure 1B. Legend reflects only the lines in the figure.
  • 30. SOLUTION # 3 RE-CODE INTERNAL VALUES OF GROUP VARIABLE 30
  • 31. WHAT IF DRUG B IS NO LONGER IN A STUDY? SGPLOT Drop Drug B We Want (Default) Drug A Drug B Drug C Placebo NOTE: Line attributes before the deleted group, namely DRUG A, remain intact. 31
  • 32. WHAT IF PLACEBO IS NOT IN A STUDY? SGPLOT Drop Placebo We Want (Default) Drug A Drug B Drug C Placebo NOTE: Line attributes are consistent. Line attributes before the deleted group remain intact. 32
  • 33. Solution # 3. RE-CODE INTERNAL VALUES OF GROUP VARIABLE  So if one knows ahead of the treatments that are going to be dropped, one can put these treatments to be dropped last, in terms of its internal value.  The line attributes for the remaining treatment groups will remain intact. 33
  • 34. Solution # 3. RE-CODE INTERNAL VALUES OF GROUP VARIABLE *- Define formats for re-coding group variable, TRT. -*; proc format; invalue INTRTF ‘Drug A’ = 1 ‘Drug B’ = 4 ‘Drug C’= 2 ‘Placebo’=3; value TRTF 1= ‘Drug A’ 2=‘Drug C’ Note that Drug B is now 3=‘Placebo’ assigned to the largest value! 4=‘Drug B’; run; *- Re-coded the value from TRT to TRT2 so that treatment groups to be -*; *- dropped have higher internal values and will be listed last. -*; data DRUG_RECODED; set DRUG (where=(TRT ne ‘Drug b’) ); TRT2=input(TRT, intrf.); label TRT2=‘Treatment: ‘; format TRT2 TRTF.; run; *- Sort the data based on the internal value of the re-coded variable -*; *- of TRT2. -*; proc sort data=DRUG_RECODED; by TRT2; 34 run;
  • 35. Solution # 3. RE-CODE INTERNAL VALUES OF GROUP VARIABLE *- Re-order the line attributes to match internal values of group variable, TRT2; proc template; define style STYLES.MYSTYLE3; parent=STYLES.MYSTYLE; style GraphData1 from GraphData1 / linestyle=1 contrastcolor=RED markersymbol=‘circle’; style GraphData2 from GraphData2 / linestyle=3 contrastcolor=GREEN markersymbol=‘diamond’; style GraphData3 from GraphData3 / linestyle=4 contrastcolor=ORANGE markersymbol=‘circlefilled’; style GraphData4 from GraphData4 / linestyle=2 contrastcolor=BLUE markersymbol=‘square’; end; Run; Note: line attributes for Drug B is now the last in the list. *- Generate Figure 3B that excludes Drug B with Re-coded variable, TRT2 -*; ods listing style=STYLES.MYSTYLES3; title ‘Score Over Time by Treatment’; proc sgplot data=DRUG_RECORDED; series y=SCORE x=MONTH / group=TRT2 markers; keylegend/noborder title=‘Treatment: ‘; 35 Run;
  • 36. SOLUTION # 4 USE INDEX OPTION IN GRAPH TEMPLATE LANGUAGE (GTL) 36
  • 37. PROC SGPLOT vs Graph Template Language (GTL) PROC SGPLOT GTL Single Cell Plot Multiple Cell Plot Quality Graphics Higher Quality Graphics Some Customization More Customization Quick and Easy to Require Significant Time Learn and Use and Effort to Learn 37
  • 38. Use of Index Options in GTL Can Ensure Line Consistency. What if you have yet to master GTL?  If you have SAS 9.3, you can use SG Attribute Map (Solution #5).  If not and if you only need a simple plot that can be produced by the SG procedure, you can use TMPLST options to get the code to create the template and then render that template. Example: proc sgplot data=DRUG tmplst=“c:alicewuss_2011_graphline_plot.sas”; series y=SCORE x=MONTH / group=TRT markers; keylegend/noborder title=‘Treatment: ‘; run; 38
  • 39. Solution # 4. USING INDEX IN GTL *- Create a variable IDVAL to associate the group variables with -*; *- line attributes defined in STYLES.MYSTYLE. -*; data DRUG_IDVAL; set DRUG (where=(TRT NE ‘Drug B’) ); if TRT=‘Drug A’ then IDVAL=1; else if TRT=‘Drug B’ then IDVAL=2; else if TRT=‘Drug C’ then IDVAL= 3; else if TRT=‘Placebo’ then IDVAL=4; run; *- Template SGPLOT was obtained from TMPLOUT options in PROC SGPLOT.-*; *- INDEX options in SERIESPLOT statement has been added manually. -*; proc template; define statgraph SGPLOT; begingraph; EntryTitle “Score Over Time by Treatment’/ textattrs=(size=2pct); layout overlay; seriesplot x=MONTH y=SCORE / primary=true group=TRT index=IDVAL display=(markers) LegendLabel=“Average Score” Name=“SERIES”; DiscreteLegend “Series” / Location=Outside Title=“Treatment: “ Border=false; endlayout; 39 endgraph; Add Manually. end; run;
  • 40. Solution # 4. USING INDEX IN GTL *- Use PROC SGRENDER to render the graph from the stored graphics -*; * Template SGPLOT. -*; ods listing style=STYLES.MYSTYLE; proc sgrender data=DRUG_IDVAL template=SGPLOT; run; 40
  • 41. SOLUTION # 5 USE OF SG ATTRIBUTE MAP (Available in SAS Version 9.3) 41
  • 42. Solution # 5. USING SG Attribute Map Approach *- Create Attribute Map Data Set named MYATTRMAP. ---*; data MYATTRMAP; retain ID “MYID”; input VALUE & $7. LINESTYLE : 3. LINECOLOR : $6 MARKERSYMBOL : $12 MARKCOLOR : $6.; cards; Drug A 1 red circle red Drug B 2 blue square blue Drug C 3 green diamond green Placebo 4 orange circlefilled orange ; run; *- Reference to MYATTRMAP to define the line attributes. -*; ods listing; title ‘Score Over Time by Treatment’; proc sgplot data=DRUG dattrmap=MYATTRMAP; series y=SCORE X=MONTH / group=TRT attrid=MYID marker; 42 keylegend / noborder title=“Treatment: “; run;
  • 44. A Panel of Graph Cells Produced by PROC SGPANEL PANELBY variables (BMI, SUBJID) controls the cell order. 44 Figure 4A: Lines are NOT consistent with the desirable line attributes.
  • 45. THE SGPANEL PROCEDURE Code for Figure 4A ods listing style=STYLES.MYSTYLE; title h=20pt ‘HbA1c (%) by Month’; proc sgpanel data=HBA1C; panelby BMI SUBJID / layout=panel columns=3 colheader=top rowheaderpos=right uniscale=row start=topleft spacing=5; series x=MONTH y=HBA1C / group=TRT name=‘HBA1C’ lineattrs=(pattern=solid thickness=3) markers; keylegend ‘HBA2C’ / noborder position=bottom title=“Treatment: “; colaxis value=(0 3 6 9 12) label=‘Month’; rowaxis label=‘HbA1c (%)’; run;  Unlike SGPLOT, in SGPANEL, the default order is controlled by the order of PANELBY variables and then the order of GROUP variable within the same panel. 45  Here, we can think of each cell as having 3 missing treatment groups.
  • 46. A Panel of Graph Cells Produced by PROC SGPANEL 46 Figure 4B: Lines are consistent with the desirable line attributes.
  • 47. THE SGPANEL PROCEDURE Code for Figure 4B (Using Index Options in GTL) ods listing style=STYLES.MYSTYLE; title h=20pt ‘HbA1c (%) by Month’; proc sgpanel data=HBA1C tmplout=“c:wuss_2011Figure4B.sas” ; panelby BMI SUBJID / layout=panel columns=3 colheader=top rowheaderpos=right uniscale=row start=topleft spacing=5; series x=MONTH y=HBA1C / group=TRT name=‘HBA1C’ lineattrs=(pattern=solid thickness=3) markers; keylegend ‘HBA2C’ / noborder position=bottom title=“Treatment: “; colaxis value=(0 3 6 9 12) label=‘Month’; rowaxis label=‘HbA1c (%)’; run; 47
  • 48. Code for Figure 4B *- Define a template name GPANEL -*; proc template; define statgraph SGPANEL; … SAS codes …; begingraph / …; EntryTitle “HbA1c (%) by Month” / textattrs=(size=20pt); layout datapanel classvars= (BMI SUBJID) / …; … SAS codes …; Add Manually. layout prototype / __SGPROC; SeriesPlot x=MONTH y=HBA1C / primary=true display=(markers) Group=TRT INDEX=INDVAL Lineattrs=(Pattern=1 Thickness=3) LegendLabel=“HbA1c” Name=“HBA1C”; endlayout; endlayout; DiscreteLegend “HBA1c” / Title=“Treatment: “ Border=false; endlayout; endgraph; end; run; ods listing style=STYLES.MYSTYLE; proc sgrender data=HBA1C template=SGPANEL; 48 run;
  • 49. ACKNOWLEDGEMENT  Art Carpenter, Caloxy  Shawn Hopkin, Seattle Genetics  Lelia McConnell, SAS Technical Support  Susan Morrison, SAS Technical Support  Marcia Surratt, SAS Technical Support 49
  • 50. The END 50