ODS GRAPHICS DESIGNERIN
SAS® 9.2 TS2M3
Edmonton SAS User Group
Oct 27, 2010
John Kirtz
Snowy Owl Software
® SAS is the registered trademark of SAS Institute Inc, North Carolina, USA
INTRODUCTIONPresentation Objectives
Introduce the Graphics Designer
Demo ODS Graphics Designer
Interactive and batch graphics
Quick Look at Graphics Template Language
Illustrate the power of language
Basic Introduction to Statistical Graphics(Handout)
targeted for casual or non-users
Components
options available to produce statistical graphics
Getting started / increasing skill levels
references to papers/ presentations / book
Sample graphics from referenced papers
encourage you to read paper
Paper /SUGI Presentation References (Handout)
quick list of most useful papers I found
INTRODUCTIONPresentation Outline
Introduction
1. ODS Graphic Designer
Overview and Basic Features
Designer and Interactive Graphics - demo
Designer and Batch Graphics - demo
Graphic Templates and Style Sheets Elements - demo
2. ODS Graphics Designer + Graphics Template Language
Overview
Graphic that cannot be built with GUI – Condition Rendering
Graphic that cannot be built with GUI – Panel Sidebar - demo
Graphic that cannot be built with GUI – Irregular Grid - demo
Closing Remarks
STATISTICAL GRAPHICS BASICSKey Elements of Statistical Graphics
Underlying ODS Graphics
New template based graphics system
New graphic template language
Components that use new technology
Automatic - Request Based Graphics
Analytic procedures (Handout)
Syntactic Tools
SAS/Graph “SG” Procedures (Handout)
Graphics Template Language (Handout)
Interactive Tools
ODS Graphic Editor (Handout)
ODS Graphic Designer
Combination of Tools
Efficient and powerful
ODS GRAPHIC DESIGNER
SECTION 1
Roadmap
SAS Help
SAS/GRAPH : Windows : ODS Graphics Designer
SAS/GRAPH 9.2: ODS Graphics Designer User’s Guide
SAS/GRAPH 9.2: Statistical Graphics Procedures Guide
SGDesign Procedure
SGRender Procedure
Papers and SUGI presentations
Using the ODS Graphics Designer to Create Your Own Templates
Philip R Holland, Holland Numerics Limited, Royston, Herts, UK
ODS Graphic Designer - An Interactive Tool for Creating Batchable Graphs
Sanjay Matange, SAS Institute Inc., Cary, NC
SAS/Graph ODS Graphics DesignerOverview
Developed for
SAS Users who use 3rd party software for graphics
SAS Users not comfortable/experienced with
SAS/Graph procedures
Templates or Graphics Template Language
SG procedures
Ease of use
Efficiency
Interactive graphical application
Java based GUI application
Create statistical graphics with point and click interface
Do not need to know
Details of templates
Graph Template Language
SAS/Graph ODS Graphics DesignerFeatures
Design sophisticated graphs
visual gallery of commonly used graphs or blank graph
wide array of plot types
complex graphs with multiple cells
dynamic columns and text
20-80 rule applies (20% of GTL used / create 80% of graphics)
Save Resulting Graphic
as image file ( png, bmp,t iff, gif, ps …)
in extendible graph gallery
as SGD file to disk
edit and/or run in batch with Proc SGDesign
Template Generator
Style Templates
Includes GUI ODS Style editor ( save modified styles)
GTL Templates
run in batch with Proc SGRender
SAS/Graph ODS Graphics DesignerProcess
Define
Library
Custom
Style
Template
Customized
Graph
Template
“SGD”
File
SAS
DMS
Graphic
Image
ODS
Graphic
Designer
Submit
%SGDesign
SAS
Session
Proc
SGRender
Proc
SGDesign
jproxy.exe
Basic Usage Customized Style Sheet Batch Mode Graphics
Custom
Graphic
Galleries
SAS/Graph ODS Graphics DesignerAnatomy of ODS Statistical Graphic
SAS/GRAPH 9.2 : Graphical Template Language Reference
1. Graph
2. Cell
3. Title
4. Plot
5. Legend
6. Axis
7. Footnote
SAS/Graph ODS Graphics DesignerDesigner and Interactive Graphics
Quick tour of designer
Create winter weather graphic
Save graphic as image and also as a Graphic Gallery Template
Use new template to plot summer weather from different dataset
SAS/Graph ODS Graphics DesignerUse Designer to Create Batch Mode Analysis Graphic
Create a graphic to examine the distribution of an arbitrary variable
Build using the distribution of the weight of people in a study (
Use “Shared Variable Graphic” and save graphic as SGD file
Use SGD file in a SAS program to examine horsepower and client income
SAS/Graph ODS Graphics DesignerUse Designer to Create Batch Mode Analysis Graphic
Use SGDesign in program
ods listing style=default;
ods graphics on / height=400px width=600px;
proc sgdesign sgd="g:\esugOct2010\sgdFiles\Distribution1.sgd" data=sashelp.cars;
dynamic v1="horsepower" v2="origin";
dynamic myTitle="Horsepower Distribution - style=default - height=400px width=600px"
myFoot="&sysdate9.";
run;
ods listing style=journal2;
ods graphics on / height=600px width=400px;
proc sgdesign sgd="g:\esugOct2010\sgdFiles\Distribution1.sgd“ data=sasdata.clientRisk;
dynamic v1="income" v2="riskcat";
dynamic myTitle="Client Income Distribution - style=journal2 - height=600px width=400px"
myFoot="&sysdate9.";
run;
ODS graphics off;
SAS/Graph ODS Graphics DesignerUse Designer to Create Batch Mode Analysis Graphic – Output 1
SAS/Graph ODS Graphics DesignerUse Designer to Create Batch Mode Analysis Graphic – Output 2
SAS/Graph ODS Graphics DesignerInteraction Between Graphic Templates and Graphic Style Elements
Graphic Style Elements and Plot Attributes
Create a custom Style with Style Editor
Hard-coded plot attributes
Export the custom style to sas program and review code in SAS editor
SAS/Graph ODS Graphics DesignerInteraction Between Graphic Templates and Graphic Style Elements
Create custom style to keep using style elements for graph element attributes
SAS/Graph ODS Graphics DesignerInteraction Between Graphic Templates and Graphic Style Elements
Style Elements vs. Hard-Coded Values
proc template;
define statgraph sgdesign;
dynamic _FAT _PROTEIN _POPULATION;
begingraph;
layout lattice _id='lattice' / columndatarange=data columngutter=10
rowdatarange=data rowgutter=10;
layout overlay _id='overlay' /;
contourplotparm _id='contour' x=_FAT y=_PROTEIN z=_POPULATION
/ contourtype=LABELEDLINEGRADIENT gridded=false
colormodel=ThreeColorRamp
lineattrs=(color=CX0000FF thickness=7)
linelabelattrs=GraphValueText(size=14 color=CXFF0000)
name='contour';
endlayout;
endlayout;
endgraph;
end;
run;
ODS GRAPHIC DESIGNER
AND
GRAPHICS TEMPLATE LANGUAGE
SECTION 2
Working with TemplatesUsing Proc Template
Create Template
only syntax checkingPROC TEMPLATE;
DEFINE STATGRAPH gName </ STORE=libref.catalog>;
DYNAMIC var1 .. varN; * link to runtime variables;
MVAR mVar1 .. mVarN; * character macro variables;
NMVAR nmVar1 .. nmVarN; * numeric runtime variables;
NOTES 'text';
GTL statements
END;
RUN;
Sample Templateproc template;
define statgraph sgdesign;
dynamic _CATEGORY _AMOUNT;
begingraph;
layout overlay _id='overlay' /;
barchart _id='bar' x=_CATEGORY y=_AMOUNT / name='bar';
endlayout;
endgraph;
end;
run;
Working with TemplatesUsing Proc SGRender
Execute Proc SGRender
%let mVar1=ABC;* define character macro variable(s);
%let nmVar1=123; * define numeric macro variable(s);
* “height” and “weight” must exist in myData;
PROC SGRENDER DATA=myData Template=gName;
Dynamic var1=“height” var2=“weight”;
RUN;
Working with TemplatesProc SGRender vs Proc SGDesign
Proc SGDesign
works only on designer files
can work with multiple datasets
Proc SGRender
works only on templates
more complex graphics possible at present
only works with a single dataset
Common Features
Support
Format Statement
Label Statement
Where statement
By Statement
Honor
ODS Destination options
ODS “Graphics on” options
Working with TemplatesGraphic that cannot be built with GUI – Condition Rendering
1. Want to build graphic that
produces a histogram if no grouping variable specified
or else produces a box plot graphic
produces different titles based on Proc SGRender statements
2. Use Designer to build required GTL code snippets
3. Extract to SAS and create / test required template
Working with TemplatesCondition Rendering Template
proc template;
define statgraph cond1;
dynamic _distVar _GROUPVAR _BYLINE_;
begingraph;
if ( exists(_GROUPVAR) )
entrytitle "Distribution by " _groupVar;
layout overlay _id='overlay' /;
boxplot _id='box_h' x=_GROUPVAR y=_distVar
/ name='box_h„ orient=horizontal;
endlayout;
else
if (exists(_BYLINE_))
entrytitle "Distribution";
entrytitle _BYLINE_;
else
entrytitle "Overall Distribution";
endif;
layout overlay _id='overlay' /;
histogram _id='histogram' _distVar / binaxis=false name='histogram';
endlayout;
endif;
endgraph;
end;
Run;
Working with TemplatesNo Group Variable defined, No By Statement
proc sgrender template=cond1 data=sasdata.usage;
dynamic _distvar="skiers“ ;
format skiers comma6.0;
label skiers ="Number of Skiers per Day";
Run;
Working with TemplatesGroup Variable defined, No By Statement
proc sgrender template=cond1 data=sasdata.usage;
dynamic _distvar="skiers" _groupvar="dayclass";
format skiers comma6.0;
label skiers ="Number of Skiers per Day";
Run;
Working with TemplatesNo Group Variable defined, By Statement
proc sort data=sasdata.usage out=t;by dayclass; run;
proc sgrender template=cond1 data=t;
dynamic _distvar="skiers" ;
by dayclass;
format skiers comma6.0;
label skiers ="# Skiers / Day";
run;
Working with TemplatesGraphic that cannot be built with GUI – Panel Sidebar
1. Build data-lattice graphic with contour plots
2. GUI will not allow gradient legend to be added
3. Extract template code and add a Sidebar legend
Working with TemplatesGraphic that cannot be built with GUI – Panel Sidebar
1. Create Panelled Graphic – Starch and Sugar as class variables
2. 0-10-20 % levels for starch & sugar, 0-10 % for fat and protein
3. GUI will not allow gradient legend to be added to panel graphic
Working with Templates
Extract Template GTL
proc template;
define statgraph sgdesign;
dynamic _FAT _PROTEIN _POPULATION _SUGAR _STARCH;
dynamic _panelnumber_;
begingraph;
layout datalattice _id='datalattice' columnvar=_STARCH rowvar=_SUGAR
/ panelnumber=_panelnumber_ cellheightmin=1 cellwidthmin=1
column2datarange=unionall columndatarange=unionall columngutter=3
headerlabeldisplay=value row2datarange=unionall rowdatarange=unionall
rowgutter=3;
layout prototype _id='prototype' / ;
contourplotparm _id='contour' x=_FAT y=_PROTEIN z=_POPULATION
/ colormodel=ThreeColorRamp contourtype=LABELEDLINEGRADIENT gridded=false
name='contour';
endlayout;
endlayout;
endgraph;
end;
run;
Graphic that cannot be built with GUI – Panel Sidebar
Working with Templates
Add Sidebar and Legend GTL. Use Proc SGRender.
proc template;
define statgraph sgdesign;
dynamic _FAT _PROTEIN _POPULATION _SUGAR _STARCH _panelnumber_;
begingraph;
layout datalattice _id='datalattice' columnvar=_STARCH rowvar=_SUGAR
/ panelnumber=_panelnumber_ cellheightmin=1 cellwidthmin=1 column2datarange=unionall
columndatarange=unionall columngutter=3 headerlabeldisplay=value row2datarange=unionall
rowdatarange=unionall rowgutter=3;
layout prototype _id='prototype' / ;
contourplotparm _id='contour' x=_FAT y=_PROTEIN z=_POPULATION
/colormodel=ThreeColorRamp contourtype=LABELEDLINEGRADIENT gridded=false name='contour';
endlayout;
sidebar / align=right;
continuouslegend _id='legend' 'contour' /
halign=right location=outside orient=vertical align=center;
endsidebar;
endlayout;
endgraph;
end;
run;
proc sgrender data=SASDATA.CULTURE template=sgdesign;
dynamic _FAT="FAT" _PROTEIN="PROTEIN" _POPULATION="POPULATION" _SUGAR="SUGAR"
_STARCH="STARCH";
run;
Graphic that cannot be built with GUI – Panel Sidebar
Working with TemplatesGraphic that cannot be built with GUI – Panel Sidebar
Final Graphic
Working with TemplatesGraphic that cannot be built with GUI – Irregular Grid
1. Want to build graphic below but GUI will not allow irregular grid
2. Use Designer to build required GTL code snippets
3. Extract to SAS and create required template
4. Work around single dataset requirement for Proc SGRender
Working with TemplatesGraphic that cannot be built with GUI – Irregular Grid
Build parts of desired graphic: two row layout, top and bottom rows
Working with Templates
Extract Two Row Template GTL
Code in red can be removed, Comments in green
proc template;
define statgraph sgdesign;
dynamic _SNOW _SNOW2;
Add dynamic statements with dynamic variables from both top and bottom graphics;
dynamic MYTITLE MYFOOT;
begingraph;
entrytitle _id='title' halign=center MYTITLE /;
entryfootnote _id='footnote' halign=right MYFOOT / textattrs=(weight=bold style=normal);
layout lattice _id='lattice' / columndatarange=data columngutter=10 rowdatarange=data
rowgutter=10 rowweights=(0.35 0.65 ) rows=2;
layout overlay _id='overlay' /;
Top row graphic GTL code goes here
histogram _id='histogram' _SNOW / binaxis=false name='histogram';
endlayout;
Bottom row graphic GTL code goes here, note replace entire row code with 2 column lattice
layout overlay _id='overlay3' /;
histogram _id='histogram2' _SNOW2 / binaxis=false name='histogram2';
endlayout;
endlayout;
endgraph;
end;
run;
Graphic that cannot be built with GUI – Irregular Grid
Working with Templates
Extract Top Row Graphic GTL
Code in blue is all that is needed, cut and insert in two row template
proc template;
define statgraph sgdesign;
dynamic _DATE _SNOW;
begingraph;
layout lattice _id='lattice' / columndatarange=data columngutter=10
rowdatarange=data rowgutter=10;
layout overlay _id='overlay' / yaxisopts=(label='Snow');
needleplot _id='needle' x=_DATE y=_SNOW
/ lineattrs=(color=CXC6C3C6 thickness=7) name='needle' yaxis=Y;
discretelegend _id='legend' 'needle' / across=1 border=true
displayclipped=true halign=right location=inside opaque=false
order=rowmajor valign=top;
endlayout;
endlayout;
endgraph;
end;
run;
Graphic that cannot be built with GUI – Irregular Grid
Working with Templates
Extract Bottom Row Graphic GTL
Code in blue is all that is needed, cut and insert in two row template
proc template;
define statgraph sgdesign;
dynamic _LIFTNAME _SKIERS _CATEGORY _AMOUNT _YEAR;
begingraph;
layout lattice _id='lattice'
/ columndatarange=data columngutter=10 columns=2 rowdatarange=data
rowgutter=10;
layout overlay _id='overlay' /;
boxplot _id='box' x=_LIFTNAME y=_SKIERS / name='box';
endlayout;
layout overlay _id='overlay2' /;
barchart _id='bar' x=_CATEGORY y=_AMOUNT/ group=_YEAR name='bar' stat=mean;
endlayout;
endlayout;
endgraph;
end;
run;
Graphic that cannot be built with GUI – Irregular Grid
Working with Templates
Final GTL ( start)
proc template;
define statgraph sgdesign;
dynamic _DATE _SNOW;
dynamic _LIFTNAME _SKIERS _CATEGORY _AMOUNT _YEAR;
dynamic MYTITLE MYFOOT;
begingraph;
entrytitle _id='title' halign=center MYTITLE /;
entryfootnote _id='footnote' halign=right MYFOOT
/ textattrs=(weight=bold style=normal);
layout lattice _id='lattice'
/ columndatarange=data columngutter=10 rowdatarange=data
rowgutter=10 rowweights=(0.35 0.65 ) rows=2;
layout overlay _id='overlay' / yaxisopts=(label='Snow');
needleplot _id='needle' x=_DATE y=_SNOW
/ lineattrs=(color=CXC6C3C6 thickness=7) name='needle' yaxis=Y;
discretelegend _id='legend' 'needle' / across=1 border=true
displayclipped=true halign=right location=inside opaque=false
order=rowmajor valign=top;
endlayout;
Graphic that cannot be built with GUI – Irregular Grid
Working with Templates
Final GTL ( finish)
layout lattice _id='lattice'
/ columndatarange=data columngutter=10 columns=2 rowdatarange=data
rowgutter=10;
layout overlay _id='overlay' /;
boxplot _id='box' x=_LIFTNAME y=_SKIERS / name='box';
endlayout;
layout overlay _id='overlay2' /;
barchart _id='bar' x=_CATEGORY y=_AMOUNT/ group=_YEAR name='bar'
stat=mean;
endlayout;
endlayout;
endlayout;
endgraph;
end;
run;
Graphic that cannot be built with GUI – Irregular Grid
Working with Templates
Final GTL (execute)
/*
Proc SGRrender can only use a single input dataset so need to combine all datasets into a single dataset;
CRITICAL: make sure all column names are unique across all input datasets,
drop or rename if necessary!*/
data t;
set sasdata.winterweather
sasdata.Liftusageweekly
sasdata.Salesweekly;
run;
proc sgrender data=t template=sgdesign;
dynamic _DATE="date" _SNOW="snow";
dynamic _LIFTNAME="liftname" _SKIERS="skiers" _CATEGORY="category“
_AMOUNT="amount" _YEAR="year";
dynamic MYTITLE="Lodge Summary Graphic" MYFOOT="&sysdate";
run;
Graphic that cannot be built with GUI – Irregular Grid
ODS STATISTICAL GRAPHICS DESIGNER
John Kirtz
Snowy Owl Software
780-998-7455
HAVE FUN !
Top Related