Loading presentation...

Present Remotely

Send the link below via email or IM

Copy

Present to your audience

Start remote presentation

  • Invited audience members will follow you as you navigate and present
  • People invited to a presentation do not need a Prezi account
  • This link expires 10 minutes after you close the presentation
  • A maximum of 30 users can follow your presentation
  • Learn more about this feature in our knowledge base article

Do you really want to delete this prezi?

Neither you, nor the coeditors you shared it with will be able to recover it again.

DeleteCancel

Make your likes visible on Facebook?

Connect your Facebook account to Prezi and let your likes appear on your timeline.
You can change this under Settings & Account at any time.

No, thanks

Hands on SAS Graphics Final

A SAS Graphics course which covers the procedures SGPLOT, SGPANEL, SGSCATTER and SGRENDER, and gives a basic introduction to GTL.
by

Kriss Harris

on 18 May 2015

Comments (0)

Please log in to add your comment.

Report abuse

Transcript of Hands on SAS Graphics Final

SGSCATTER
GTL
SGRENDER
SGPLOT
SGPANEL
proc sgplot data = boxplots;
vbox results / category = Treatment;
run;
Scatterplot
Boxplot
ods html style = statistical;
proc sgplot data = data;
scatter x = B y = A;
run;
hbox
Bar Chart
proc sgplot data = boxplots;
vbar Treatment / response = results STAT = MEAN ;
run;
hbar
The other STAT options that are FREQ and SUM, SUM is the default.
SAS 9.4 offers Median and Percent
Quiz 1
STATEMENT X=var Y=var / options;
STATEMENT response-var / options;
STATEMENT category-var / options;
Means and Confidence Intervals
(for one factor)
proc sgplot data = boxplots;
vline Treatment / response = results STAT = MEAN LIMITSTAT = CLM markers;
run;
(for more complicated models)
Means and Confidence Intervals
ods output lsmeans = lsmeans;
proc mixed data = boxplots;
class treatment day;
model results = treatment day;
lsmeans treatment / cl;
run;
proc sgplot data = lsmeans;
scatter x = treatment y = estimate / YERRORLOWER
= lower YERRORUPPER = upper;
series x = treatment y = estimate;
run;
Fit the Model
Plot the graph
Scatterplot with different markers for each group
proc sgplot data = merged;
scatter x = bodyweight y = Results / group = treatment;
run;
Used to change the size,
symbol and color of the
marker.
Scatterplot with regression slopes
for each treatment group
proc sgplot data = merged;
reg x = bodyweight y = Results / group = treatment;
run;
Scatterplot with different markers for each group
proc sgplot data = merged;
scatter x = bodyweight y = Results / group = treatment;
reg x = bodyweight y = Results / nomarkers;
run;
prevents
more markers
from being
produced
Quiz 2
Using noautolegend
SGPLOT Concepts
Basic Plots
Distribution Plots
Categorisation Plots
Fit and Confidence
Step, Band, Bubble, Needle, Vector Plots
Scatter, Series, High-Low
Regression
Bar Charts, Line Charts
Box plots, Histograms, and Normal
and Kernel density estimates
Dot Plots, Waterfall Plots
SGPLOT Overlay Compatibility
Fit and Confidence
Basic Pl ts
Distribution Plot
Categorisation Plot
PLOTS
OPTIONS
proc sgplot data = merged noautolegend;
reg x = bodyweight y = Results / group = treatment;
run;
Inset Statement
proc sgplot data = merged noautolegend;
reg x = bodyweight y = Results / group = treatment;
inset "Protocol: YYY0001112" "Date: 26.08.09" / position = bottomright BORDER;
run;
Other position options are
Bottom, Bottomleft, Left, Right, Top,
Topleft and Topright.
Using separate strings places the
New string on a separate line.
Axis labels
proc sgplot data = scatter;
yaxis label = "Treatment A Response";
xaxis label = "Treatment B Response";
scatter x = B y = A;
run;
Other options for xaxis and yaxis statements include:
values – specify values or intervals:
i.e. values=(0 to 20 by 2) values=(1 3 10 to 50 by 5) values=(2 3 4 5 6)
min – specify minimum value of axis – i.e. min=0
max – specify maximum value of axis – i.e. max=100
Changing Marker Properties
proc sgplot data = scatter;
scatter x = B y = A / MARKERATTRS = (color = red size = 12 symbol = circlefilled);
yaxis label = "Treatment A Response";
xaxis label = "Treatment B Response";
run;
Marker Symbols
Adding a Reference Line
proc sgplot data = scatter;
scatter x = B y = A / MARKERATTRS = (size = 12 symbol = circlefilled color = red);
refline 100 / axis = y LINEATTRS = (color = black) ;
yaxis label = "Treatment A Response";
xaxis label = "Treatment B Response";
run;
Lineattrs for pattern
Quiz 3
ADVANCED OPTIONS
Changing Axis Font Size
proc template;
define style MyStyleDefault;
parent=Styles.statistical;
style GraphLabelText from GraphLabelText / fontsize = 14px;
style GraphValueText from GraphValueText / fontsize = 12px;
end;
run;
PROC Template
ods html style = MyStyleDefault;
proc sgplot data = scatter;
yaxis label = "Treatment A Response";
xaxis label = "Treatment B Response";
scatter x = B y = A;
run;
Controlling Symbol and Line Options
for each group %modstyle macro
http://support.sas.com/documentation/cdl/en/statug/63347/HTML/default/viewer.htm#statug_odsgraph_sect056.htm
Reference
%modstyle(
parent=statistical,
name=plotmod,
type=CLM,
colors=black blue,
fillcolors=colors,
markers=diamondfilled starfilled
);
Cycles through colors, line, and markers simultaneously
type = LMbyC
type = CbyLM
Adding Jitter
data boxplots_jittered;
set boxplots;
if treatment = "Treatment A" then trtcode = 10;
else if treatment = "Treatment B" then trtcode = 20;
treatment_jittered = trtcode + ranuni(10) - 0.5;
label treatment_jittered = "Treatment";
run;

proc format;
value trtfmt 9.5 - 11.5 = "Treatment A"
19.5 - 20.5 = "Treatment B"
other = " ";
run;
Adding Jitter
Adding Jitter
proc sgplot data = boxplots_jittered;
scatter y = results x = treatment_jittered / group = treatment_jittered ;
format treatment_jittered trtfmt. ;
xaxis label = "Treatment" values = (10,20)
valueshint offsetmax = 0.1 offsetmin = 0.1;
run;
Minimum and Maximum axis values are determined
independently of the values you specify in the
VALUES= option.

Useful as some of the jittered values will be less
than 10 and more than 20.
Leaving some room between the
left hand and right hand side of the graph
Making a new numerical variable for treatment
Using the Format Statement to recode the
Treatments so that the character value is
displayed on the axis
Adding a value between 0 and 1 to each
of the treatment codes,
and then subtracting 0.5 so the tick mark
is in the middle
SGPANEL Concepts
The SGPANEL procedure has a required PANELBY statement that is used to define the classifier variables for the panel. This statement must be specified before any plot, axis, or legend statement or else an error occurs.

The SGPANEL procedure creates the same plots as the SGPLOT procedure, the only difference is that you can panel them in SGPANEL.

The SGPANEL and SGPLOT procedures contain the same statements except that there is a PANELBY statement in Proc SGPANEL and there are COLAXIS and ROWAXIS statements instead of XAXIS and YAXIS.
Boxplot panelled by day
proc sgpanel data = boxplots;
panelby day;
vbox results / category = Treatment;
run;
proc sgpanel data = boxplots;
panelby day / columns = 1 novarname;
vbox results / category = Treatment;
run;
Boxplot Panelled by day
for 6 days
proc sgpanel data = boxplots_all;
panelby day / novarname;
vbox results / category = Treatment;
run;
proc sgpanel data = boxplots_all;
panelby day / novarname uniscale = column;
vbox results / category = Treatment;
run;
proc sgpanel data = boxplots_all;
panelby day / novarname uniscale = column
spacing = 10;
vbox results / category = Treatment;
run;
Both rows have the
same scales, and the
second row has values all
above 100.
Only makes the rows have a
scale that fits each cell within that
row.
Specifies the number of pixels
between the rows and columns
in the panel.
Quiz 4
proc sgpanel data = boxplots_all;
panelby day / options??? ;
vbox results / category = Treatment;
run;
Questions
?
Exercise 2
Proc SGSCATTER
Useful for having a panel of plots that have at least one independent axis
PLOT Statement - 2 independent axis i.e. x and y
COMPARE Statement - 1 independent axis i.e. just x
Useful for producing a matrix of plots
MATRIX Statement
Independent x and y axis
PLOT Statement
proc sgscatter data=sashelp.cars;
plot mpg_highway*weight msrp*horsepower;
run;
Different variables
Different x variables
COMPARE statement
proc sgscatter data=sashelp.cars;
compare y=mpg_highway x=(weight enginesize horsepower) / group = type;
run;
Different x variables
Matrix Plot
MATRIX statement
proc sgscatter data=sashelp.iris
(where=(species eq 'Virginica'));
matrix petallength petalwidth sepallength
/ ellipse=(type=mean)
diagonal=(histogram kernel);
run;
3 Variables
Therefore produces 3 * 3 matrix plot
Quiz 5
MATRIX?
PLOT?
COMPARE?
Questions
?
Graph Template Language
The SAS/GRAPH Graph Template Language (GTL) is an extension to the Output Delivery System (ODS) that enables you to create sophisticated analytical graphics that are not available from traditional SAS/GRAPH and SG procedure statements.

Creating graphs using GTL is a two step process:

The GTL templates are defined with PROC TEMPLATE in the form of a STATGRAPH template.

The GTL templates are rendered using the SGRENDER procedure, which specifies a data source that contains appropriate data values and the template to use for rendering the graph.

GTL Reference link: http://support.sas.com/documentation/cdl/en/grstatgraph/65377/HTML/default/viewer.htm
Obtaining GTL Code
(for Boxplot example)
proc sgplot data = boxplots tmplout = "C:\Template_for_boxplots.sas" ;
vbox results / category = Treatment;
run;
Obtained GTL Code
For Boxplot
For Scatterplot
Looks daunting at
first but the only real
difference is within
the layout statement
proc template;
define statgraph sgplot;
begingraph;
layout overlay;
ScatterPlot X=Treatment Y=Results / primary=true
LegendLabel="Results" NAME="SCATTER";
endlayout;
endgraph;
end;
run;
Code is nested
similar to HTML
or do loop.
Why is GTL Overlay useful?
proc sgrender data=boxplots template=sgplot;
run;
SGRENDER
plots the template
In SGPLOT you cannot
overlay a boxplot with any
other plot but you can in GTL!
proc template;
define statgraph sgplot;
begingraph;
layout overlay / xaxisopts=(type=Discrete);
BoxPlot X=Treatment Y=Results;
ScatterPlot X=Treatment Y=Results;
endlayout;
endgraph;
end;
run;
LAYOUT LATTICE and OVERLAY
You don't have to always memorise the code. It can be outputted it by using tmplout in SG Procedures
proc template;
define statgraph sgmypanel;
begingraph;

layout lattice;

layout overlay /
xaxisopts=(type=Discrete LABEL = "Treatment") yaxisopts = (LABEL = "Results");
BoxPlot X=Treatment Y=Results;
endlayout;

layout overlay;
ScatterPlot X=Treatment Y=Results;
endlayout;

endlayout;

endgraph;
end;
run;
The lattice layout is a multicell layout that combines features of gridded and overlay layouts
and offers reserved areas for additional formatting:
4 sidebars (top, bottom, left, and right) that span all rows and columns
individual row and column headings
individual cell headings
axis scaling on a per cell, per row, per column, all rows, or all columns basis
Lattice Layout
LAYOUT LATTICE, OVERLAY and GRIDDED
layout lattice / columns = 2;

layout overlay /
xaxisopts=(type=Discrete) LABEL = "Treatment" yaxisopts = (LABEL = "Results");
BoxPlot X=Treatment Y=Results;
endlayout;

layout overlay;
ScatterPlot X=Treatment Y=Results;

layout gridded /
columns=2 border=TRUE autoalign=(BottomLeft TopLeft TopRight);
entry "Mean of Dataset:"; entry "Mean";
entry "Std Dev of Dataset:"; entry "Std Dev";
endlayout;

endlayout;

endlayout;
Lattice
Overlay
(or gridded)
Using Dynamic Variables
Created a Dynamic Variable called _VAR_
Using the statement: (after Proc Template)
Dynamic _VAR_;
layout gridded /
columns=2 border=TRUE autoalign=(BottomLeft TopLeft TopRight);
entry "Mean of Dataset:"; entry eval(strip(put(mean(_VAR_),8.2)));
entry "Std Dev of Dataset:"; entry eval(strip(put(stddev(_VAR_),8.2)));
endlayout;
Using EVAL to calculate the mean
and standard deviation
proc sgrender data=boxplots template=sgmypanel;
dynamic _var_ = "Results";
run;
Rendering with
SGRENDER
Setting the dynamic variable to equal Results.
Quiz 6
The Gridded Layout
is the simplest organisation
of cells and can be used to
enter text!
Lattice layout = multicell layout
LAYOUT OVERLAY is useful for
superimposing plots
What's the easiest way to obtain GTL Code?
Best for superimposing plots?
Best for complex multicell layouts?
Best for entering text?
Questions?
?
proc sgplot data = merged;
scatter x = bodyweight y = Results / group = treatment;
run;
proc sgplot data = merged;
reg x = bodyweight y = Results / group = treatment;
run;
proc sgplot data = merged;
scatter x = bodyweight y = Results / group = treatment;
reg x = bodyweight y = Results / nomarkers;
run;
Which code produces this output?
Which words below are not real plot statements?
refline
inset
set
inref
Hands on SAS Graphics Procedures I
Presented by Kriss Harris
italjet125@yahoo.com
SAS 9.2
SG Procedures began in SAS 9.2.

Since then more plot statements and options have been added to SAS 9.3 and SAS 9.4.
SAS 9.4
SAS 9.3
Differences between SAS v9.2, 9.3 and 9.4

Additional Plot Statements in SAS 9.3 compared to 9.2
BUBBLE
HBARPARM
HIGHLOW
LINEPARM
VBARPARM
WATERFALL (Pre Production)

Additional Plot Options in SAS 9.3 compared to 9.2
Attribute Maps
Annotation
More options related to By Group Processing
Jittering Scatterplots
More control of attributes related to plot, i.e. Medianattrs

Additional Plot Statements in SAS 9.4 compared to 9.3
STYLEATTRS
BLOCK
DROPLINE
FRINGE
GRADLEGEND
POLYGON
SYMBOLCHAR
SYMBOLIMAGE
TEXT
XAXISTABLE
YAXISTABLE

Additional Plot Options in SAS 9.4 compared to 9.3
Border and Wall options
Specifying the number of decimal places
Apply dataskin to plots
Control outlines of markers and bars

Loess, Penalized B-Spline Curves, Ellipses
Exercise 1
filename source url

"http://krissharris.co.uk/cdiscpilotproject/adam/datasets/adlbc.xpt"
;
libname source xport
;

data
work.adlbc ;

set
source.adlbc ;
run
;
Obtain ADBLC dataset and produce a
Boxplot
of aval by (scheduled) visit for the lab parameter Creatinine (umol/L).

Note: The plot will not look that good at the moment, and we work on improving it later on.
Clustered Box Plot
proc sgplot data = adlbc;
where param = "Creatinine (umol/L)";
vbox aval / category = visitnum group = trta groupdisplay=cluster ;
run;
discrete group
Changing Order of Group
proc sgplot data = adlbc;
where param = "Creatinine (umol/L)";
vbox aval / category = visitnum group = trta groupdisplay=cluster grouporder = descending ;
run;
Differences at SGPLOT and SGPANEL Level
Agenda
Morning
SGPLOT
SGPANEL
SGSCATTER

Afternoon
Graph Template Language (GTL)

Which Procedure to use?
Creating Graphs
SGPLOT
Single-cell graphs
SGPANEL
Multi-cell graphs
SGSCATTER
Graphs with independent axis
Matrix Plots
GTL
Complex Graphs
GTL
SGPLOT
SGPANEL
SGSCATTER
Using PROC SGPLOT for Quick High-Quality Graphs
Susan J. Slaughter
Lora D. Delwiche
Adding Jitter
proc sgplot data = boxplots;
scatter y = results x = treatment / group = treatment jitter;
run;
Attribute Maps
data myattrmap;
length markercolor $5 markersymbol $13;
input ID $1-4 value $6-17 markercolor $ markersymbol $;
datalines;
myid Treatment A black diamondfilled
myid Treatment B blue starfilled
;
run;
proc sgplot data = boxplots dattrmap = myattrmap;
scatter y = results x = treatment / group = treatment
attrid = myid
;
run;

http://support.sas.com/documentation/cdl/en/grstatproc/65235/HTML/default/viewer.htm#p0teue0ztycuidn14cciruv038ur.htm
Text Conventions
Blue
- up to SAS 9.3
Orange
- if you only have SAS 9.2
Green
- new in SAS 9.4
Annotation
TAILORED PLOTS
Venn Diagram
Napoleon Plot
Provides good summary of how plot statements work
Reference: http://support.sas.com/resources/papers/proceedings09/158-2009.pdf
Annotate your SGPLOT Graphs
Reference: http://www.pharmasug.org/proceedings/china2014/CC/PharmaSUG-China-2014-CC01.pdf
Annotate Functions
Plot Statements in SAS 9.2
BAND
DENSITY
DOT
ELLIPSE
HBAR
HBOX
HISTOGRAM
HLINE
INSET
KEYLEGEND
LOESS


NEEDLE
PBSPLINE
REFLINE
REG
SCATTER
SERIES
STEP
VBAR
VBOX
VECTOR
VLINE
Scatter
proc sgplot data = adlbc2;
by param;
where ablfl ne "Y" and visitnum = 4;
scatter x = base y = aval;
run;
Series (Not Sorted)
proc sgplot data = adlbc2;
ods graphics on / reset = all imagename = "series_not_sorted";
proc sgplot data = advs;
by param;
series x = ady y = aval / group = trta ;
run;
Series

proc sort data = advs out = advs_series_sorted;
by param ady;
run;
High Low

proc sgplot data = adae;
by usubjid;
where usubjid = "01-718-1427";
highlow y = aedecod low = astdy high = aendy / group = aesev type = bar barwidth = 0.8;
run;
Step

ods graphics on / reset = all imagename = "step";
proc sgplot data = surv2;
step x = aval y = survival / group = trta;
scatter x = aval y = survival / group = trta markerattrs = (symbol = plus);
run;

proc sgplot data = advs_series_sorted;
by param;
series x = ady y = aval / group = trta ;
run;
Band (not sorted)

proc sgplot data = reg_estimates;
by param;
band y = pred lower = lower upper = upper;
run;
Band

proc sort data = reg_estimates out = reg_estimates_sorted;
by param pred;
run;
Band with Scatter

proc sgplot data = reg_estimates_sorted;
by param;
band y = pred lower = lower upper = upper;
scatter x = base y = aval; /* scatterplot labels are used regardless of order */
run;
Bubble

proc sgplot data = adlbc2;
by param;
where ablfl ne "Y" ;
bubble x = visitnum y = aval size = base ;
run;

proc sgplot data = reg_estimates_sorted;
by param;
band y = pred lower = lower upper = upper;
xaxis label = "Actual";
run;
Vbar (Comparison with Needle Plot)

proc sgplot data = adlbc2;
by param;
where racen = 2;
vbar adt / response = aval group = sex stat = mean;
run;
Needle
proc sgplot data = adlbc2;
by param;
where racen = 2;
needle x = adt y = aval / group = sex lineattrs = (thickness = 2);
run;
Vector
proc sgplot data = adlbc2;
by param;
where ablfl ne "Y";
scatter x = visitnum y = aval;
vector x = x1 y = y1 / xorigin = 10 yorigin = 160 lineattrs = (color = black thickness = 2);
run;
Reg
proc sgplot data = adlbc2;
by param;
where ablfl ne "Y";
reg x = base y = aval;
run;
Loess
proc sgplot data = adlbc2;
by param;
where ablfl ne "Y";
loess x = base y = aval;
run;
Pbspline
proc sgplot data = adlbc2;
by param;
where ablfl ne "Y";
pbspline x = base y = aval;
run;
Ellipse
proc sgplot data = adlbc2;
by param;
where ablfl ne "Y";
ellipse x = base y = aval;
run;
No axis labels
by default
Ellipse (with labels)
proc sgplot data = adlbc2;
by param;
where ablfl ne "Y";
ellipse x = base y = aval;
xaxis label = "Baseline Creatinine (umol/L) values";
yaxis label = "Post-baseline Creatinine (umol/L) values";
run;
Hbox
proc sgplot data = adlbc2;
by param;
hbox aval / category = visitnum;
run;

Vbox
proc sgplot data = adlbc2;
by param;
vbox aval / category = visitnum;
run;
Histogram
proc sgplot data = adlbc2;
by param;
histogram aval;
run;
Density
proc sgplot data = adlbc2;
by param;
density aval;
run;
Hbar
proc sgplot data = adlbc2;
by param;
hbar visitnum / response = aval stat = mean;
run;
Hline
proc sgplot data = adlbc2;
by param;
hline visitnum / response = aval stat = mean;
run;
Hbar and Hline (wrong order)
proc sgplot data = adlbc2;
by param;
hline visitnum / response = aval stat = mean;
hbar visitnum / response = aval stat = mean;
run;
Hbar and Hline
proc sgplot data = adlbc2;
by param;
hbar visitnum / response = aval stat = mean;
hline visitnum / response = aval stat = mean;
run;
Vbar
proc sgplot data = adlbc2;
by param;
vbar visitnum / response = aval stat = mean;
run;
Vline
proc sgplot data = adlbc2;
by param;
vline visitnum / response = aval stat = mean;
run;

Vbarparm (Hbarparm)
proc sgplot data = waterfall_group2;
vbarparm category = start response = pchgb / group = group grouporder = ascending;
format start order.;
xaxis label = "Patient";
yaxis label = '% Change From Baseline';
run;

Waterfall
Plot
Waterfall (Pre-Production)
proc sgplot data = waterfall_group2;
waterfall category = start response = pchgb / colorgroup = group;
format start order.;
xaxis label = "Patient";
yaxis label = 'Stacked % Change From Baseline';
run;

Others
Inset, Keylegend, Refline
Inset
ods escapechar = "*";
proc sgplot data = adlbc2 noautolegend;
by param;
where ablfl ne "Y";
inset "R*{sup '2'} = 0.8278" / border position = topleft;
reg x = base y = aval / nomarkers lineattrs = (thickness = 0); /* Not displaying for now */
run;

Inset and Reg
ods escapechar = "*";
ods graphics on / reset = all imagename = "inset_and_reg";
proc sgplot data = adlbc2;
by param;
where ablfl ne "Y";
inset "R*{sup '2'} = 0.8278" / border position = topleft;
reg x = base y = aval;
run;

Keylegend (default)
proc sgplot data = adae;
by usubjid;
where usubjid = "01-718-1427";
highlow y = aedecod low = astdy high = aendy / group = aesev type = bar barwidth = 0.8 name = "aesevg";
run;

Keylegend 1
proc sgplot data = adae;
by usubjid;
where usubjid = "01-718-1427";
highlow y = aedecod low = astdy high = aendy / group = aesev type = bar barwidth = 0.8 name = "aesevg";
keylegend "aesevg" / across = 1;
run;

Keylegend 2
proc sgplot data = adae;
by usubjid;
where usubjid = "01-718-1427";
highlow y = aedecod low = astdy high = aendy / group = aesev type = bar barwidth = 0.8 name = "aesevg";
keylegend "aesevg" / location = inside across = 1;
run;
Refline (using column)
proc sgplot data = adlbc2;
by param;
where ablfl ne "Y";
reg x = base y = aval;
refline A1LO / axis = y;
run;
Refline (gender split)
proc sgplot data = adlbc2;
by param;
where ablfl ne "Y" and sex = "M";
reg x = base y = aval;
refline A1LO / axis = y;
refline A1HI / axis = y;
run;

Refline (gender split with range)
proc sgplot data = adlbc2;
by param;
where ablfl ne "Y" and sex = "M";
reg x = base y = aval;
refline A1LO / axis = y;
refline A1HI / axis = y;
yaxis min = 60;
run;

Before Xaxistable
proc sgplot data = adlbc4 noautolegend;
vbarparm category = visitnum response = avgvisit;
scatter x = visitnum y = nlabel / markerchar = nvisitc y2axis;
scatter x = visitnum y = avglabel / markerchar = avgvisitc y2axis;
yaxis offsetmin = 0.2 label = "Mean Analysis Value";
y2axis type = discrete display = (nolabel) offsetmax = 0.85;
run;
Xaxistable
proc sgplot data = adlbc2;
vbar visitnum / response = aval stat = mean;
xaxistable aval / stat = freq location = inside;
xaxistable aval / stat = mean location = inside;
run;
Can edit label in
later release
Wouldn't join treatments
in real life.
Wouldn't typically plot Unscheduled visits
Special thanks to Adrienne Bonwick for reviewing the presentation.
proc template;
define statgraph sgplot;
dynamic _ticklist_;
begingraph;
layout overlay / xaxisopts=(type=Discrete
discreteOpts=(tickValueList=_ticklist_));
BoxPlot X=Treatment Y=Results / SortOrder=Internal primary=true
LegendLabel="Results" NAME="VBOX";
endlayout;
endgraph;
end;
run;
layout overlay / xaxisopts=(type=Discrete);
BoxPlot X=Treatment Y=Results;
endlayout;
layout overlay;
ScatterPlot X=Treatment Y=Results;
endlayout;
Key Components of GTL
Plots
Layouts
BANDPLOT
BARCHART
BARCHARTPARM
BIHISTOGRAM3DPARM
BLOCKPLOT
BOXPLOT
BOXPLOTPARM
BUBBLEPLOT
CONTOURPLOTPARM
DENDROGRAM
DENSITYPLOT
DROPLINE
ELLIPSE
ELLIPSEPARM
FRINGEPLOT
HEATMAPPARM
HIGHLOWPLOT
HISTOGRAM
HISTOGRAMPARM

LINEPARM
LOESSPLOT
MODELBAND
MOSAICPLOTPARM
NEEDLEPLOT
PBSPLINEPLOT
PIECHART
REFERENCELINE
REGRESSIONPLOT
SCATTERPLOT
SCATTERPLOTMATRIX
SERIESPLOT
STEPPLOT
SURFACEPLOTPARM
VECTORPLOT
WATERFALLCHART
More Plots
available in GTL
A lot of statements
end with "PLOT"
Single-cell layouts
LAYOUT OVERLAY
LAYOUT REGION
LAYOUT OVERLAYEQUATED
LAYOUT OVERLAY3D
Multi-cell adhoc layouts
LAYOUT GRIDDED
LAYOUT LATTICE
Multi-cell classification panels
Other
LAYOUT DATALATTICE
LAYOUT DATAPANEL
LAYOUT PROTOTYPE*
LAYOUT GLOBALLEGEND
Lattice Layout Schematic Internal Axis
Lattice Layout Schematic External Axis
More LAYOUT LATTICE examples
Adding p-values to figures

ENTRY

ENTRY

BOXPLOT

VECTORPLOT

Adding p-values to figures
An easier way to think off the figure

More LAYOUT LATTICE examples
Kaplan Meier Survival Curve
GTL Minimalist Solution

Scatterplot

Entry

Entry

StepPlot

4 Cells

Kaplan Meier Survival Curve
GTL Minimalist Solution

Example GTL Code for Kaplan Meier
Part 1

Example GTL Code for Kaplan Meier
Part 2

6 CELLS

The Lattice Layout options: Rows, Columns, Rowweights and Columnweights control the layout.
Napoleon Plot (Final Time)

Scatterplot X = cohort_label_x
Y = order_subject /
markercharacter = cohort_label markercharacterattrs=(size=9px);


Step 4
Plotting Cohort Information

Scatterplot X = length Y = order_subject / group =id_response_markers;

DiscreteLegend "Response_Markers"/ type = marker exclude = ("A" "D" "O" "PD")
location = outside valign = bottom down = 2 across = 4 title="Reason for
Treatment Discontinuation”;


Step 2
Plotting Treatment Discontinuation Markers and Legend

DiscreteAttrMap name="Response_Markers";

Value "A" "Adverse Event" / markerattrs=(color=GraphData4:color symbol=squarefilled);

EndDiscreteAttrMap;

DiscreteAttrVar attrvar=id_response_markers var=result attrmap="Response_Markers";


Step 2
Treatment Discontinuation Attributes

DiscreteAttrMap name="Visit_Dose_Group";

Value "1-50" "2-50" "3-50" "4-50" / fillattrs=(color= GraphData1:color) lineattrs=(color=black pattern=solid);

EndDiscreteAttrMap;

DiscreteAttrVar attrvar=id_visit_dose_group var=VISIT_DOSE attrmap="Visit_Dose_Group";



Step 1
Code for Bar Chart Attributes

DiscreteAttrMap name="Dose_Group";

Value "50" /
fillattrs=(color=GraphData1:color) lineattrs=(color=black pattern=solid);

EndDiscreteAttrMap;

DiscreteAttrVar attrvar=id_dose_group var=DOSE attrmap="Dose_Group";


Step 1
Code for Dose Legend Attributes

Step 1
Bar Chart and Dose Legend

The Data

You can create a Napoleon Plot in GTL with these statements:
DISCRETEATTRMAP
DISCRETEATTRVAR
LAYOUT OVERLAY
BARCHARTPARM
SCATTERPLOT
DISCRETELEGEND


How to Create a Napoleon Plot

In Phase I clinical trials
We’re interested in examining the patients treatment duration.
We’re interested in the actual dose taken.
We’re interested in knowing the reason a patient discontinued study.
A Napoleon Plot will give you the platform to assess exposure and subject disposition.

Why Would You Want to Create a Napoleon Plot?

The Napoleon Plot is a very useful plot for assessing treatment safety at each interim.
For each subject the extent of exposure, the reason for treatment discontinuation and the assigned cohort is displayed.
The drawback of using this method to produce a Napoleon Plot is the visit and dose combination have to be manually entered.

Conclusion

** Maxlegend area is very important here, as we are displaying 2 legends **;

ods graphics on / reset = all maxlegendarea = 30 width = 3in height = 2in ;


Important Options

Step 4
Cohort Information

Scatterplot X = length
Y = order_subject /
markercharacter = result_label markercharacterattrs=(size=10px);


Step 3
Plotting Treatment Discontinuation Initials

Step 3
Treatment Discontinuation Initials

layout overlay /
xaxisopts=(offsetmin=0 label="Days on Treatment”)
yaxisopts=(label="Subject” reverse = true type=discrete);

BarChartParm X=order_subject Y=cycledays / barwidth=0.8 orient=horizontal Group=id_visit_dose_group;

DiscreteLegend "Dose_Group"/ type = fill location = inside title = "Dose”;
endlayout;


Step 1
Plotting Bar Chart and Dose Legend

Cohort
Information

Napoleon Plot

Napoleon Plot

Presented by Kriss Harris

Napoleon Plot

Step 2
Treatment Discontinuation Legend

Reason for
Treatment
Discontinuation

Napoleon Plot

Treatment
Dose

Napoleon Plot

Treatment
Cycles

Napoleon Plot

How to improve your figure
Konrad Żywno
LAYOUT DATAPANEL
Similar to Proc SGPANEL
Scatterplot
Scatterplot code
proc template;
define statgraph scatterpanel;
begingraph;
layout datapanel classvars = (param);
layout prototype;
scatterplot x = visitnum y = aval / group = trta;
endlayout;
endlayout;
endgraph;
end;
run;

proc sgrender data = adlbc_all template = scatterpanel;
where paramcd in ("ALT", "AST") and anl01fl = "Y";
run;
Boxplotparm
proc sort data = adlbc_all;
by param paramcd visitnum trta;
run;

proc univariate data = adlbc_all noprint;
where anl01fl = "Y" and paramcd in ("ALT", "AST");
by param paramcd visitnum trta;
var aval;
output out = boxplotstats Min = Min Max = Max Median = Median Mean = Mean Q1 = q1 q3 = q3;
run;

proc transpose data = boxplotstats out = boxplotstats2;
by param paramcd visitnum trta;
var Median Mean q1 q3 Min Max;
run;
Calculate Summary Statistics
Create Plot
proc template;
define statgraph boxplotpanel;
begingraph;
layout datapanel classvars = (param);
layout prototype;
boxplotparm x = visitnum y = col1 stat = _NAME_ / group = trta groupdisplay = cluster name = "trtleg";
endlayout;

sidebar;
discretelegend "trtleg";
endsidebar;

endlayout;
endgraph;
end;
run;

ods graphics on / reset = all imagename = "boxpanel";
proc sgrender data = boxplotstats2 template = boxplotpanel;
where paramcd in ("ALT", "AST");
run;
proc template;
define statgraph boxplotpanellog;
begingraph;
layout datapanel classvars = (param) /
rowaxisopts = (type = log label = "Lab Intensity Values");
layout prototype;
boxplotparm x = visitnum y = col1 stat = _NAME_ /
group = trta groupdisplay = cluster name = "trtleg";
endlayout;

sidebar;
discretelegend "trtleg";
endsidebar;
endlayout;
endgraph;
end;
run;

ods graphics on / reset = all imagename = "boxpanellog";
proc sgrender data = boxplotstats2 template = boxplotpanellog;
where paramcd in ("ALT", "AST");
run;
Axis options within LAYOUT DATAPANEL
Create Legend within SIDEBAR statement
Occasionally need to Derive Statistics First
Annotate Example
data anno1;
infile datalines dlm = '#';
length x1space $11 y1space $9 x2space $11 y2space $9 label $17;
input function $ x1 y1 label x2 y2 textcolor $ linecolor $ height width x1space $ y1space $ x2space $ y2space $ direction $ anchor $ ;
datalines;
oval # 98 # 35 # # . # . # blue # # 4 # 4 # wallpercent #datavalue # wallpercent #datavalue # #
arrow# 95 # 34 # # 85 # 25 # # blue # . # . # wallpercent #datavalue # wallpercent #datavalue #IN # TOPRIGHT
text # 83 # 25 # Potential Outlier # . # # # # . # 20 # wallpercent #datavalue # wallpercent #datavalue # # TOPRIGHT
;
run;
ods graphics / reset = all imagename = "scatteranno";
proc sgplot data = boxplots sganno = anno1;
scatter y = results x = treatment / group = treatment;
run;
http://www.phusewiki.org/docs/Conference%202014%20CS%20Presentations/CS06.pdf
Good Reference:
Aim
1. Interactive

2. Challenging

3. Fun

Order has changed
Typically will only
plot scheduled visits
Questions
?
Source dataset = Boxplot.
Annotate the highest value in Treatment 2 by adding a circle around the value and draw an arrow pointing to the value.
Label the annotation potenial outlier.

Exercise 3
Source dataset = ADLBC
Subset dataset on analysis flag and the first two paramcd's (ALT and AST).
Produce a panelled Box Plot of Aval by Visit, and panel by Param.
Layout should be 1 column and 2 rows.
LAYOUT OVERLAY controls axis options.
Good References
Graphically speaking blog:
http://blogs.sas.com/content/graphicallyspeaking/

Searching PharmaSUG, SAS Global Forum Papers and PhUSE papers

Matange, Sanjay. November 2013. Getting Started with the Graph Template Language in SAS: Examples, Tips, and Techniques for Creating Custom Graphs. Cary, North Carolina. SAS Institute.
CONCLUSIONS
Thank you
I would like to thank Syntax for Science, in particularly Juan Vicente Torres, Azahara Moreno for organising this Training Course.

I would to thank you all guys for attending.
Conclusions
SGPLOT: Single-Cell Plots.
SGPANEL: Multi-Cell Plots.
SGSCATTER: Independent-axis.

GTL: Complex Graphics. Everything that you can do in the SG Procedures, can be done in GTL.
Square Scatter Plot
ods graphics on / reset = all height = 3in width = 3in
proc sgplot data = adlbc2;
by param;
where ablfl ne "Y" and visitnum = 4;
scatter x = base y = aval;
run;
Which statement produce which plots?
The code can be downloaded at:
http://www.krissharris.co.uk/sasgraphicscourse/pg/code.sas
The datasets can be downloaded at:
http://www.krissharris.co.uk/sasgraphicscourse/data/datasets.zip
Full transcript