Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Sas Plots Graphs


Published on

Base SAS,
Advanced SAS,
Proc SQl,
SAS in financial industry,
Clinical trials,
SAS Macros,
SAS on Unix,
SAS on Mainframe,
SAS interview Questions and Answers,
SAS Tips and Techniques,
SAS Resources,
SAS Certification questions...


Published in: Technology, Business
  • Be the first to comment

Sas Plots Graphs

  1. 1. SASTechies [email_address]
  2. 2. <ul><li>Creating </li></ul><ul><ul><li>SAS Tables, </li></ul></ul><ul><ul><li>Listings, </li></ul></ul><ul><ul><li>Basic Statistics Procedures with SAS </li></ul></ul><ul><ul><li>Graphs </li></ul></ul><ul><ul><li>ODS HTML </li></ul></ul><ul><ul><li>Proc Report and Other Utility Procedures </li></ul></ul>11/13/09 SAS Techies 2009 TLG’s
  3. 3. <ul><li>proc format; </li></ul><ul><li>value $repfmt 'TFB'='Bynum' 'MDC'='Crowley' 'WKK'='King'; </li></ul><ul><li>value cntyfmt 12='Durham' 45='Wake' 13='Orange'; </li></ul><ul><li>run; </li></ul><ul><li>proc print data=vcrsales; </li></ul><ul><li>var salesrep county unitsold; </li></ul><ul><li>format salesrep $ repfmt . County cntyfmt . ; run; </li></ul>11/13/09 SAS Techies 2009
  4. 4. <ul><li>title1 'Heart Rates for Patients with'; </li></ul><ul><li>title3 'Increased Stress Tolerance Levels'; </li></ul><ul><li>In SAS listing output , title line 2 appears blank </li></ul><ul><li>In HTML output , title lines simply appear consecutively, without extra spacing to indicate skipped title numbers. </li></ul><ul><li>TITLE < n> ' title-text ';     </li></ul><ul><li>where n is a number from 1 to 10 that specifies the title line, and 'title-text' is the actual title to be displayed. </li></ul><ul><li>The maximum title length depends on your operating environment and the value of the linesize=option </li></ul><ul><li>Title statement is global and additive </li></ul><ul><li>Cancelling titles </li></ul><ul><li>A TITLE statement remains in effect until you modify it, cancel it, or end your SAS session. </li></ul><ul><li>Redefining a title line cancels any higher-numbered title lines. </li></ul><ul><li>To cancel all previous titles, specify a null TITLE statement </li></ul>11/13/09 SAS Techies 2009 Heart Rates for Patients with Increased Stress Tolerance Levels Obs RestHR MaxHR RecHR 2 68 171 133 3 78 177 139 8 70 167 122 11 65 181 141 14 74 152 113 15 75 158 108 20 78 189 138
  5. 5. <ul><li>FOOTNOTE < n> ' footnote-text ';     where n is a number from 1 to 10 that specifies the footnote line, and footnote-text is the actual footnote to be displayed. </li></ul><ul><li>The maximum footnote length depends on your operating environment and the value of the LINESIZE= option. </li></ul><ul><li>Be sure to match quotation marks that enclose the footnote text. </li></ul><ul><li>Footnote statement is global and additive </li></ul>11/13/09 SAS Techies 2009 Obs RestHR MaxHR RecHR 2 68 171 133 3 78 177 139 8 70 167 122 11 65 181 141 14 74 152 113 15 75 158 108 20 78 189 138 Data from Treadmill Tests 1st Quarter Admissions
  6. 6. <ul><li>how to create single plots and overlaid plots, then refine the plots by scaling axes, defining plotting symbols, and specifying methods of interpolating plotted points. </li></ul><ul><li>GPLOT procedure </li></ul><ul><li>PROC GPLOT DATA= SAS-data-set ;         PLOT vertical-variable*horizontal-variable ; RUN; </li></ul>11/13/09 SAS Techies 2009
  7. 7. <ul><li>proc gplot data=clinic.totals2000; plot newadmit*month; run; </li></ul><ul><li>PLOT vertical-variable*horizontal-variable /             VAXIS= <value-list | range>             HAXIS= <value-list | range > ; </li></ul><ul><li>Ex. vaxis=10 to 100 by 10 </li></ul>11/13/09 SAS Techies 2009
  8. 8. <ul><li>PLOT vertical-variable-1*horizontal-variable             vertical-variable-2*horizontal-variable /   OVERLAY; </li></ul><ul><li>If the OVERLAY option were not specified, each plot request would generate a separate graph </li></ul><ul><li>SYMBOL statement is used to enhance your plots by specifying plotting symbols, plot lines, color, and interpolation. </li></ul><ul><li>Interpolation is a technique for estimating values between plot points and drawing lines to connect the points. </li></ul>11/13/09 SAS Techies 2009 proc gplot data=clinic.totals2000; plot therapy*month treadmill*month / overlay ; run; |<--pair1-->| |<---pair2--->|
  9. 9. <ul><li>symbol1 color=red value=star interpol=spline height=1 cm width=4; proc gplot data=clinic.totals2000; </li></ul><ul><li>plot therapy*month; run; </li></ul>11/13/09 SAS Techies 2009 symbol1 color=red value=star interpol=spline height=1 cm width=4; symbol2 color=green value=plus interpol=spline height=1 cm width=4;   VALUE=   plotting symbol   HEIGHT=   height of the plotting symbol   INTERPOL=     interpolation technique   WIDTH=   thickness of the line in pixels   COLOR=   color of plotting symbols or lines 
  10. 10. <ul><li>Setting Plotting Symbols The VALUE= (or V= ) option specifies the plotting symbol that represents each data point. Possible values for the VALUE= option include </li></ul><ul><li>the letters A through W </li></ul><ul><li>the numbers 0 through 9 </li></ul><ul><li>a number of special symbols including PLUS , STAR , SQUARE , DIAMOND , TRIANGLE , and many others </li></ul><ul><li>NONE , which produces a plot with no symbols for data points. </li></ul>11/13/09 SAS Techies 2009
  11. 11. <ul><li>Setting Plotting Symbol Height You can use the HEIGHT= (or H= ) option to specify the height of the plotting symbol. You can specify a value for height and a unit of measurement. Valid units are </li></ul><ul><li>percentage of the display area ( PCT ) </li></ul><ul><li>inches ( IN ) </li></ul><ul><li>centimeters ( CM ) </li></ul><ul><li>points ( PT ) </li></ul><ul><li>character cells ( CELL ), which is the default unit. </li></ul>11/13/09 SAS Techies 2009 symbol1 value=triangle height=1 cm color=black;
  12. 12. <ul><li>symbol1 value=triangle interpol=none ; </li></ul><ul><li>Specifying Connecting Lines To specify whether or not to connect plotted points, you use the INTERPOL= (or I= ) option in the SYMBOL statement. Connecting lines can be straight lines, smoothed lines, or vertical lines drawn from plotted points to a horizontal line at zero or the minimum value on the Y axis. </li></ul><ul><li>Possible values include NONE , JOIN , NEEDLE , SPLINE , HILO , STD , and more. </li></ul>11/13/09 SAS Techies 2009
  13. 13. <ul><li>  SYMBOL statements are both global and additive . This means that </li></ul><ul><li>once defined, they remain in effect until you change/cancel/or end the SAS session </li></ul><ul><li>within one SYMBOL statement, you can change the value of one option value without affecting the values of other options. </li></ul><ul><li>Ex: symbol1 value=square color=blue interpol=needle; </li></ul><ul><li>symbol1 v=triangle; </li></ul>11/13/09 SAS Techies 2009
  14. 14. <ul><li>Canceling SYMBOL Statement Options </li></ul><ul><li>an individual option </li></ul><ul><li>symbol1 interpol=join color=yellow width=1.5; </li></ul><ul><li>symbol1 color=; </li></ul><ul><li>all options in one SYMBOL statement </li></ul><ul><li>symbol1 interpol=join color=yellow width=2 value=square; </li></ul><ul><li>symbol2 interpol=join color=blue width=2 value=star; </li></ul><ul><li>symbol2; - Submitting the null SYMBOL2 statement cancels the SYMBOL2 statement but does not affect higher or lower numbered SYMBOL statements. </li></ul><ul><li>all SYMBOL statements currently in effect. </li></ul><ul><li>cancel all SYMBOL statements in effect by submitting statement: </li></ul><ul><li>goptions reset=symbol; </li></ul><ul><li>When you cancel a SYMBOL statement option, you return the option to its default value. </li></ul>11/13/09 SAS Techies 2009
  15. 15. <ul><li>symbol1 value=triangle interpol=none color=red; proc gplot data=clinic.totals2000; </li></ul><ul><li>plot newadmit*month; </li></ul><ul><li>run; </li></ul><ul><li>quit; </li></ul><ul><li>To end the procedure, you must submit another PROC step, a DATA step, or a QUIT statement (shown below). quit; </li></ul><ul><li>Not all procedures support RUN-group processing, and implementation varies. </li></ul>11/13/09 SAS Techies 2009
  16. 16. 11/13/09 SAS Techies 2009 symbol1 interpol=spline value=none color=red; symbol2 interpol=spline value=none color=blue; proc gplot data=clinic.therapy1999; plot swim*month aerclass*month/overlay; where swim>35 and aerclass>35; run;
  17. 17. <ul><li>proc gplot data=air.airqual; </li></ul><ul><li>plot avgtsp*month =state / </li></ul><ul><li>vminor=3 hminor=0 </li></ul><ul><li>areas=2 nolegend; </li></ul><ul><li>pattern1 color=red; </li></ul><ul><li>pattern2 color=blue; </li></ul><ul><li>note move=(10, 19) </li></ul><ul><li>color=red 'Alabama'; </li></ul><ul><li>note move=(10, 20) color= blue 'California'; </li></ul><ul><li>symbol1 c=red i=spline v=none; </li></ul><ul><li>symbol2 c=blue i=spline v=none; </li></ul><ul><li>where state in (&quot;CA&quot; , &quot;AL&quot;); </li></ul><ul><li>quit; </li></ul>11/13/09 SAS Techies 2009
  18. 18. <ul><li>PROC GCHART < DATA= SAS-data-set > ;         chart-form chart-variable </ options > ; RUN; </li></ul><ul><li>SAS-data-set is the name of the SAS data set to be used. </li></ul><ul><li>chart-form is HBAR, HBAR3D, VBAR, VBAR3D, PIE, or PIE3D. The chart-form specifies a 2D or 3D horizontal bar chart, vertical bar chart, or pie chart, respectively. </li></ul><ul><li>chart-variable is the variable that determines the number of bars or pie slices. </li></ul><ul><li>The default statistic for GCHART is FREQ (frequency). </li></ul>11/13/09 SAS Techies 2009
  19. 19. <ul><li>proc gchart; </li></ul><ul><li>hbar company; </li></ul><ul><li>run; </li></ul><ul><li>PROC GCHART < DATA= SAS-data-set > ;         chart-form chart-variable / TYPE= statistic ; RUN; QUIT; </li></ul><ul><li>Statistics include </li></ul><ul><li>CFREQ (cumulative frequency), PERCENT (percent), and CPERCENT (cumulative percent). </li></ul><ul><li>For horizontal bar charts , unless otherwise specified, PROC GCHART also displays the statistics CFREQ PERCENT , and CPERCENT </li></ul><ul><li>CFREQ  and CPERCENT  are NOT available for pie charts . </li></ul>11/13/09 SAS Techies 2009
  20. 20. <ul><li>proc gchart; vbar company / sumvar=balancedue ; run; </li></ul><ul><li>SUMVAR= option to summarize a variable within categories. </li></ul><ul><li>When you specify SUMVAR=, the default statistic is SUM , so the chart displays the total of the values of the summary variable for each unique value of the chart variable. </li></ul><ul><li>When you use SUMVAR=, you can also use TYPE=. However, the value of TYPE= can be only SUM or MEAN . </li></ul>11/13/09 SAS Techies 2009 proc gchart; vbar company / sumvar=balancedue type=mean ;
  21. 21. <ul><li>proc gchart; </li></ul><ul><li>vbar company / sumvar=balancedue type=mean patternid=midpoint ; run; </li></ul><ul><li>enhance your charts by specifying patterns other than the default values for bars or slices. </li></ul><ul><li>PATTERNID= <BY | MIDPOINT | GROUP | SUBGROUP> where BY , MIDPOINT , GROUP , or SUBGROUP specify that bar colors and/or patterns vary according to the option specified. </li></ul><ul><li>You cannot use the PATTERNID=MIDPOINT option when you create pie charts. </li></ul>11/13/09 SAS Techies 2009
  22. 22. <ul><li>proc gchart data=clinic.admit; hbar sex / sumvar=weight type=mean group=actlevel patternid=group ; run; </li></ul><ul><li>pattern1 color=lib ; pattern2 color=lig ; proc gchart data=clinic.admit; hbar age / sumvar=weight type=mean </li></ul><ul><li>subgroup=sex </li></ul><ul><li>patternid=subgroup mean; run; </li></ul>11/13/09 SAS Techies 2009
  23. 23. <ul><li>pie company / sumvar=balancedue type=mean fill=x ; </li></ul><ul><li>FILL= <X|S> where </li></ul><ul><li>X changes the fill pattern for all slices to hatch </li></ul><ul><li>S changes the fill pattern for all slices to solid. </li></ul><ul><li>You cannot use the FILL= option with bar charts. </li></ul>11/13/09 SAS Techies 2009
  24. 24. <ul><li>proc gchart; pie3d company / sumvar=balancedue type=mean ctext=blue explode= &quot;ACME&quot;; where Company in (&quot;ACME&quot;, &quot;RURITAN&quot;, &quot;USA INC.&quot;); run; </li></ul><ul><li>pattern1 color=lib; </li></ul><ul><li>pattern2 color=lig; </li></ul><ul><li>proc gchart data=clinic.admit; </li></ul><ul><li>hbar3d age / sumvar=weight type=mean subgroup=sex patternid=subgroup mean; run; </li></ul>11/13/09 SAS Techies 2009
  25. 25. <ul><li>To save graphs in a SAS catalog other than the default catalog, you use the GOUT= option in the PROC statement for the step that creates your graph. So, when you create charts, you specify GOUT= in the PROC GCHART statement. </li></ul><ul><li>Ex: </li></ul><ul><li>symbol1 interpol=spline value=none color=red; </li></ul><ul><li>symbol2 interpol=spline value=none color=blue; </li></ul><ul><li>proc gchart data=clinic.therapy1999 gout=newcat ; </li></ul><ul><li>vbar month / sumvar=swim type=sum; </li></ul><ul><li>hbar month / sumvar=aerclass type=sum; </li></ul><ul><li>where swim>35 and aerclass>35; </li></ul><ul><li>run; </li></ul>11/13/09 SAS Techies 2009