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 ...
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...
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 in a Flash
/* Chart Area Options */                       AXIS2
GOPTIONS xpixels=&_EGCHARTWIDTH                   lab...
Customise Code

• Global Options
    – Set default values and picture size
    – Output to create a graphics image
*create...
Customise Code

• Titles and Footnotes
TITLE1 font=”Arial” height=12pt justify=center “This is My Title”;
TITLE2 font=”Ari...
Customise Code

• Alter the look of the bars (Pattern Statement)
PATTERN1 COLOR=yellow; *note: default is for solid bar co...
Customise Code

• Controlling the Axis look and feel
AXIS1   order = 0 to 500000 by 100000
        label=(font=Arial heigh...
Customise Code

 • The Chart Procedure
PROC GCHART DATA=SASHELP.PRDSALE;
   vbar3d REGION /
   SUBGROUP=PRODTYPE
   SUMVAR...
What did we Change?
Before           After
Making Further Customisations

• Use the annotate facility
  –   Add text labels
  –   Add values
  –   Add lines, bars an...
Create an Annotate Dataset
ata anno ;                                     position = '6';
  length function color $ 8 text...
Tell Gchart to use Annotate
proc gchart data=sashelp.prdsale;
• Your Subtopics Go Here
   vbar3d region /
   subgroup=prod...
Automating to Produce Multiple
        Graphs?
        • Change to one graph per Region?
                           Duplic...
Automate with Macro Code

• Only have to maintain one piece of code
• Use macros to substitute key filters and
  parameter...
Automate with Macro Code
%macro byRegion(title1=,region=,axis=);
*note: must be set to ods listing to output to a bitmap t...
Generates multiple graphs
NOTE: RECORDS WRITTEN TO c:tempbar EAST.emf
 • Your Subtopics Go Here
NOTE: There were 720 obser...
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 fi...
Output to Word Automatically
Output to Excel Automatically

• Can output direct to Excel using DDE
  – Insert to a specific cell location using R1C1 St...
Output to Excel Automatically
systask command '"c:program filesMicrosoft OfficeOfficeexcel.exe"' nowait;
 • Your Subtopics...
Output to Excel Automatically
Graph N Go
• Quick way to create graphs in SAS
  – Type GRAPHNGO on the command line



                                  ...
Graph N Go

• Very easy to generate multiple graphs per page
• Export as HTML file, image or image catalog in
  SAS
• Can ...
Resources Available

SAS Online Doco – SAS/Graph Software: Reference
Lots of samples on the SAS web site ….
   http://supp...
Questions??
Upcoming SlideShare
Loading in...5
×

2004 Wendy Osborne

559

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
559
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
7
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

2004 Wendy Osborne

  1. 1. Sunz 2004 SAS Wizardry Tips and Techniques for SAS/Graph resented by Wendy Osborne
  2. 2. 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?
  3. 3. SAS Graph … lots of options
  4. 4. Where to Start… • You must have SAS/Graph Licensed • Set up the code • Automate It - ideal for updating multiple graphs on a regular basis
  5. 5. Code in a Flash • Enterprise Guide – Graph Wizard
  6. 6. Code in a Flash
  7. 7. Code in a Flash • Your Subtopics Go Here
  8. 8. Code in a Flash
  9. 9. Code in a Flash
  10. 10. Code in a Flash • Your Subtopics Go Here Creates all key SAS program Code required
  11. 11. 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;
  12. 12. 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 ;
  13. 13. 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";
  14. 14. 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;
  15. 15. 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
  16. 16. 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;
  17. 17. What did we Change? Before After
  18. 18. 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!
  19. 19. 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;
  20. 20. 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
  21. 21. 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
  22. 22. 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
  23. 23. 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);
  24. 24. 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
  25. 25. Automate into Word or Excel
  26. 26. Output to Word Automatically • SAS can output direct to Word using DDE and Word Bookmarks
  27. 27. 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;
  28. 28. Output to Word Automatically
  29. 29. Output to Excel Automatically • Can output direct to Excel using DDE – Insert to a specific cell location using R1C1 Style
  30. 30. 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;
  31. 31. Output to Excel Automatically
  32. 32. Graph N Go • Quick way to create graphs in SAS – Type GRAPHNGO on the command line Select Data Build up multiple Graphs In Workspace
  33. 33. Graph N Go • Very easy to generate multiple graphs per page • Export as HTML file, image or image catalog in SAS • Can print direct
  34. 34. 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/
  35. 35. Questions??
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×