2004 Wendy Osborne
Upcoming SlideShare
Loading in...5
×
 

2004 Wendy Osborne

on

  • 848 views

 

Statistics

Views

Total Views
848
Views on SlideShare
848
Embed Views
0

Actions

Likes
0
Downloads
6
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    2004 Wendy Osborne 2004 Wendy Osborne Presentation Transcript

    • Sunz 2004 SAS Wizardry Tips and Techniques for SAS/Graph resented by Wendy Osborne
    • 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 program Code required
    • Code in a Flash /* Chart Area Options */ AXIS2 GOPTIONS xpixels=&_EGCHARTWIDTH label=('Region') ypixels=&_EGCHARTHEIGHT; MINOR=NONE; PATTERN1 COLOR=CX4A97ED; TITLE "Sales by Region"; FOOTNOTE "Created by Wendy Osborne"; /* Symbol Statements */ ; PROC GCHART DATA=SASHELP.PRDSALE ; LEGEND1 vbar3d REGION / LABEL=(FONT='MS Sans Serif' HEIGHT=12pt SUBGROUP=PRODTYPE JUSTIFY=CENTER 'Product type' ) SUMVAR=ACTUAL POSITION=(BOTTOM CENTER OUTSIDE) LEGEND=LEGEND1 FRAME RAXIS=AXIS1 CFRAME=CXE8E8E8 MAXIS=AXIS2 CBORDER=GRAY; AUTOREF SHAPE=Block /* Axes Statements */ TYPE=sum AXIS1 COUTLINE=BLACK LABEL=(FONT='Microsoft Sans Serif' FRAME HEIGHT=12pt JUSTIFY=RIGHT 'Actual Sales' ) DESCRIPTION="Sales by Region"; MINOR=NONE; RUN;QUIT;
    • Customise Code • Global Options – Set default values and picture size – Output to create a graphics image *create pointer to external directory to store graphics image; filename outgraph ‘c:tempbargraph.emf’; *set global options; goptions device=emf gsfname=outgraph gsfmode=replace xpixels=600 ypixels=600 ftext="Arial Narrow" htext=18pt cback=white ;
    • Customise Code • Titles and Footnotes 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";
    • Customise Code • Alter the look of the bars (Pattern Statement) PATTERN1 COLOR=yellow; *note: default is for solid bar colors; PATTERN2 COLOR=red; *For a line graph use…..; SYMBOL width=1 color=blue;
    • Customise Code • Controlling the Axis look and feel AXIS1 order = 0 to 500000 by 100000 label=(font=Arial height=14pt justify=center 'Actual Sales' ) value = (font=”Arial” height=10pt) MINOR=NONE; Response Axis (RAXIS) is the Y Axis Midpoint and Group Axis (MAXIS GAXIS) relate to the X axis
    • Customise Code • The Chart Procedure PROC GCHART DATA=SASHELP.PRDSALE; vbar3d REGION / SUBGROUP=PRODTYPE SUMVAR=ACTUAL LEGEND=LEGEND1 Stack the bars RAXIS=AXIS1 MAXIS=AXIS2 AUTOREF Points to the axis SHAPE=Block statements TYPE=sum COUTLINE=BLACK FRAME RUN; QUIT;
    • 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!
    • Create an Annotate Dataset ata anno ; position = '6'; length function color $ 8 text style $ 50; style = '"Arial"'; retain when 'A' size 1 ; color = 'magenta'; • Your Subtopics Go Here set sum_for_annotate; *only do this once; function = 'label'; text = 'This is my box I drew!'; if _n_ = 1 then output; do; end; *draw a box; *draw inside graph on axis values; xsys = '3'; if region = 'EAST' then ysys = '3'; do; x = 5; xsys = '2'; y = 5; ysys = '2'; function = 'move'; xc = region; output; y = actual; x = 6; color = 'black'; y = 6; position = '2'; color = 'blue'; style = '"Arial"'; style = 'solid'; function = 'label'; function = 'bar'; text = put(actual,dollar20.); output; output; *write some text; end; xsys = '3'; run; ysys = '3'; x = 7; y = 5.5;
    • Tell Gchart to use Annotate proc gchart data=sashelp.prdsale; • Your Subtopics Go Here vbar3d region / subgroup=prodtype sumvar=actual Annotation legend=legend1 raxis=axis1 maxis=axis2 width=30 space=10 autoref shape=block type=sum coutline=black annotate=anno frame; run; quit; Annotation
    • Automating to Produce Multiple Graphs? • Change to one graph per Region? Duplicate code for each region or Use macro code GRAPH2: Actual Sales GRAPH1: Actual Sales Region WEST Region EAST Actual Sales Actual Sales $200,000.00 $250,000.00 $180,000.00 $160,000.00 $200,000.00 $140,000.00 $120,000.00 $150,000.00 $100,000.00 $80,000.00 $100,000.00 $60,000.00 $40,000.00 $50,000.00 $20,000.00 $0.00 $0.00 CONSUMER EDUCATION CONSUMER EDUCATION Product Type FURNITURE Product Type FURNIT Division OFFICE Division OFFICE reated on 28th November 2004 Created on 28th November 2004
    • Automate with Macro Code • 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 %macro byRegion(title1=,region=,axis=); *note: must be set to ods listing to output to a bitmap to a directory!; • Your Subtopics Go Here *otherwise it is redirected to a temporary html library!; ods html close; ods listing; filename outgraph "c:tempbar &region..emf"; title1 font="Arial" color=blue height=20pt justify=center "&title1"; title2 font="Arial" height=18pt justify=center "Region &region"; axis1 order = &axis length=28 label = (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);
    • Generates multiple graphs NOTE: RECORDS WRITTEN TO c:tempbar EAST.emf • Your Subtopics Go Here NOTE: There were 720 observations read from the data set SASHELP.PRDSALE. WHERE region='EAST'; NOTE: PROCEDURE GCHART used: real time 0.08 seconds cpu time 0.07 seconds 2612 %byRegion(title1=GRAPH2: Actual Sales, region=WEST); NOTE: RECORDS WRITTEN TO c:tempbar WEST.emf NOTE: There were 720 observations read from the data set SASHELP.PRDSALE. WHERE region='WEST'; NOTE: PROCEDURE GCHART used: real time 0.08 seconds cpu 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
    • Output to Word Automatically *start word • Your Subtopics Go Here options noxwait noxsync; systask command '"c:program filesmicrosoft officeofficewinword.exe"' nowait; *open the word document filename windde dde 'winword|system'; data _null_; file windde; put '[FileOpen .Name = "C:temptemplate.doc" ]'; run; *go to a specific bookmark and insert the picture data _null_; file windde; put '[EditGoTo .Destination="Graph1"]'; put '[InsertPicture .Name="c:tempbar 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
    • Output to Excel Automatically systask command '"c:program filesMicrosoft OfficeOfficeexcel.exe"' nowait; • Your Subtopics Go Here *----- OPEN EXCEL share prices spreadsheet; filename cmds dde "excel|system"; data _null_; file cmds; put '[open("c:temptemplate.xls")]'; put '[SELECT("R5C5")]'; put '[insert.picture("c:tempbar west.emf")]'; put '[save.as("c:tempddeoutput.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 Graphs In 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: Reference Lots of samples on the SAS web site …. http://support.sas.com/techsup/sample/sample_graph.html http://support.sas.com/rnd/datavisualization/papers/sugi27/ http://support.sas.com/rnd/samples/graph/
    • Questions??