2004 wendy osborne
DESCRIPTION
TRANSCRIPT
SAS WizardryTips and Techniques for SAS/Graph
Presented byWendy Osborne
Sunz 2004
Excel Graphs?
• Generally just a pain... OK for simple stuff
• Why waste hours playing with Excel graph wizards when you can do it all in SAS?
SAS Graph … lots of options
Where to Start…
• You must have SAS/Graph Licensed
• Set up the code
• Automate It - ideal for updating multiple graphs on a regular basis
Code in a Flash
• Enterprise Guide – Graph Wizard
Code in a Flash
Code in a Flash
• Your Subtopics Go Here
Code in a Flash
Code in a Flash
Code in a Flash
• Your Subtopics Go Here
Creates all key SAS programCode required
Code in a Flash/* Chart Area Options */GOPTIONS xpixels=&_EGCHARTWIDTH
ypixels=&_EGCHARTHEIGHT;
PATTERN1 COLOR=CX4A97ED;
/* Symbol Statements */;
LEGEND1LABEL=(FONT='MS Sans Serif' HEIGHT=12pt JUSTIFY=CENTER 'Product type' )POSITION=(BOTTOM CENTER OUTSIDE)FRAMECFRAME=CXE8E8E8CBORDER=GRAY;
/* Axes Statements */AXIS1
LABEL=(FONT='Microsoft Sans Serif' HEIGHT=12pt JUSTIFY=RIGHT 'Actual Sales' )MINOR=NONE;
AXIS2label=('Region')MINOR=NONE;
TITLE "Sales by Region";
FOOTNOTE "Created by Wendy Osborne";
PROC GCHART DATA=SASHELP.PRDSALE;vbar3d REGION /SUBGROUP=PRODTYPESUMVAR=ACTUALLEGEND=LEGEND1RAXIS=AXIS1MAXIS=AXIS2AUTOREFSHAPE=BlockTYPE=sumCOUTLINE=BLACKFRAMEDESCRIPTION="Sales by Region";
RUN;QUIT;
Customise Code
*create pointer to external directory to store graphics image;filename outgraph ‘c:\temp\bargraph.emf’;
*set global options;goptions device=emf gsfname=outgraph gsfmode=replace xpixels=600
ypixels=600 ftext="Arial Narrow" htext=18pt cback=white ;
• Global Options– Set default values and picture size– Output to create a graphics image
Customise Code
TITLE1 font=”Arial” height=12pt justify=center “This is My Title”;TITLE2 font=”Arial” height=10pt justify=left “This is My Second title”;
footnote1 font="Arial" height=16pt justify=left "Created on 28th November 2004";
• Titles and Footnotes
Customise Code
PATTERN1 COLOR=yellow; *note: default is for solid bar colors;PATTERN2 COLOR=red;
*For a line graph use…..;
SYMBOL width=1 color=blue;
• Alter the look of the bars (Pattern Statement)
Customise Code
AXIS1 order = 0 to 500000 by 100000label=(font=Arial height=14pt justify=center 'Actual Sales' )value = (font=”Arial” height=10pt)MINOR=NONE;
• Controlling the Axis look and feel
Response Axis (RAXIS) is the Y AxisMidpoint and Group Axis (MAXIS GAXIS) relate to the X axis
Customise Code
• The Chart ProcedurePROC GCHART DATA=SASHELP.PRDSALE;
vbar3d REGION /SUBGROUP=PRODTYPESUMVAR=ACTUALLEGEND=LEGEND1RAXIS=AXIS1MAXIS=AXIS2AUTOREFSHAPE=BlockTYPE=sumCOUTLINE=BLACKFRAMERUN;
QUIT;
Stack the bars
Points to the axis statements
What did we Change?Before After
Making Further Customisations
• Use the annotate facility– Add text labels– Add values– Add lines, bars and polygons– Create your own custom legends– Can be used to build a graph from scratch!
• Your Subtopics Go Here
Create an Annotate Dataset
• Your Subtopics Go Here
data anno ;length function color $ 8 text style $ 50;retain when 'A' size 1 ;set sum_for_annotate;*only do this once;if _n_ = 1 thendo;
*draw a box;xsys = '3';ysys = '3';x = 5;y = 5;function = 'move';output;x = 6;y = 6;color = 'blue';style = 'solid';function = 'bar';output;*write some text;xsys = '3';ysys = '3';x = 7;y = 5.5;
position = '6';style = '"Arial"';color = 'magenta';function = 'label';text = 'This is my box I drew!';output;
end;*draw inside graph on axis values;
if region = 'EAST' thendo;
xsys = '2';ysys = '2';xc = region;y = actual;color = 'black';position = '2';style = '"Arial"';function = 'label';text = put(actual,dollar20.);output;
end;run;
• Your Subtopics Go Here
Tell Gchart to use Annotate
• Your Subtopics Go Hereproc gchart data=sashelp.prdsale;
vbar3d region /subgroup=prodtypesumvar=actuallegend=legend1raxis=axis1maxis=axis2width=30space=10autorefshape=blocktype=sum coutline=blackannotate=annoframe;
run;quit;
Annotation
Annotation
Automating to Produce Multiple Graphs?
• Change to one graph per Region?Duplicate code for each region orUse macro code
GRAPH2: Actual SalesRegion WEST
Created on 28th November 2004
Product Type FURNITUREOFFICE
Actual Sales
$0.00
$20,000.00
$40,000.00
$60,000.00
$80,000.00
$100,000.00
$120,000.00
$140,000.00
$160,000.00
$180,000.00
$200,000.00
Division
CONSUMER EDUCATION
GRAPH1: Actual SalesRegion EAST
Created on 28th November 2004
Product Type FURNITUREOFFICE
Actual Sales
$0.00
$50,000.00
$100,000.00
$150,000.00
$200,000.00
$250,000.00
Division
CONSUMER EDUCATION
• Only have to maintain one piece of code• Use macros to substitute key filters and
parameters– Build multiple graphs per region– Substitute default font style and size– Set axis order statements– Set default colours– Set output file names– Set titles and footnotes
Automate with Macro Code
• Your Subtopics Go Here
Automate with Macro Code
• Your Subtopics Go Here%macro byRegion(title1=,region=,axis=);*note: must be set to ods listing to output to a bitmap to a directory!;*otherwise it is redirected to a temporary html library!;ods html close;ods listing;
filename outgraph "c:\temp\bar ®ion..emf";title1 font="Arial" color=blue height=20pt justify=center "&title1";title2 font="Arial" height=18pt justify=center "Region ®ion";axis1
order = &axislength=28label = (font="Arial" height=18pt justify=center 'Actual Sales' )value = (font="Arial" height=14pt)minor = none;
More statements here….
%mend;%byRegion(title1=GRAPH1: Actual Sales,region=EAST,axis=0 to 250000 by 50000);%byRegion(title1=GRAPH2: Actual Sales,region=WEST,axis=0 to 200000 by 20000);
• Your Subtopics Go Here
Generates multiple graphs
• Your Subtopics Go HereNOTE: RECORDS WRITTEN TO c:\temp\bar EAST.emfNOTE: There were 720 observations read from the data set SASHELP.PRDSALE.
WHERE region='EAST';NOTE: PROCEDURE GCHART used:
real time 0.08 secondscpu time 0.07 seconds
2612 %byRegion(title1=GRAPH2: Actual Sales, region=WEST);
NOTE: RECORDS WRITTEN TO c:\temp\bar WEST.emfNOTE: There were 720 observations read from the data set SASHELP.PRDSALE.
WHERE region='WEST';NOTE: PROCEDURE GCHART used:
real time 0.08 secondscpu time 0.07 seconds
Directory Output
Automate into Word or Excel
Output to Word Automatically
• SAS can output direct to Word using DDE and Word Bookmarks
• Your Subtopics Go Here
Output to Word Automatically
• Your Subtopics Go Here*start wordoptions noxwait noxsync;systask command '"c:\program files\microsoft office\office\winword.exe"' nowait;*open the word documentfilename windde dde 'winword|system';data _null_;
file windde;put '[FileOpen .Name = "C:\temp\template.doc" ]';
run;*go to a specific bookmark and insert the picturedata _null_;
file windde;put '[EditGoTo .Destination="Graph1"]';put '[InsertPicture .Name="c:\temp\bar WEST.emf"]';
run;
Output to Word Automatically
Output to Excel Automatically
• Can output direct to Excel using DDE– Insert to a specific cell location using R1C1 Style
• Your Subtopics Go Here
Output to Excel Automatically
• Your Subtopics Go Heresystask command '"c:\program files\Microsoft Office\Office\excel.exe"' nowait;*----- OPEN EXCEL share prices spreadsheet;filename cmds dde "excel|system";
data _null_;file cmds;put '[open("c:\temp\template.xls")]';put '[SELECT("R5C5")]';put '[insert.picture("c:\temp\bar west.emf")]';put '[save.as("c:\temp\ddeoutput.xls")]';
run;filename cmds clear;
Output to Excel Automatically
Graph N Go
• Quick way to create graphs in SAS– Type GRAPHNGO on the command line
Select Data
Build up multiple GraphsIn Workspace
Graph N Go
• Very easy to generate multiple graphs per page• Export as HTML file, image or image catalog in
SAS• Can print direct
Resources Available
SAS Online Doco – SAS/Graph Software: ReferenceLots of samples on the SAS web site ….
http://support.sas.com/techsup/sample/sample_graph.htmlhttp://support.sas.com/rnd/datavisualization/papers/sugi27/http://support.sas.com/rnd/samples/graph/
Questions??
Sunz 2004