+ All Categories
Home > Documents > September 2015 Common Graphs In SAS · 2015. 9. 29. · September 2015 Common Graphs In SAS by...

September 2015 Common Graphs In SAS · 2015. 9. 29. · September 2015 Common Graphs In SAS by...

Date post: 23-Jan-2021
Category:
Upload: others
View: 1 times
Download: 0 times
Share this document with a friend
35
September 2015 Common Graphs In SAS by Sudip Shrestha High quality graphs can be produced using vari- ous graphical procedures in SAS. This document focuses on using pro- cedures like SGPLOT, SGPANEL, SGSCAT- TER, TEMPLATE and SGRENDER to generate high quality graphs in SAS (SAS 9.3 was used). Variety of graphs including box plots, scatter plots, bar charts (horizontal and vertical), histograms and time series plots can be produced using SGPLOT procedure. Similarly, charts by groups can be created using SGPANEL procedure. This docu- ment also illustrates how to customize parameters in the graph such as title, y-axis, x-axis, color of graph, font size and so on. Along with the graph types I have also documented the data used to create those graphs. Observing the structure of data presented here helps to understand organize your own data to produce subsequent charts. I have also provided some examples of using different ODS STYLE and EXPORTING or SAVING graphs in different format including PDF, JPG and PNG. The main purpose here is to know how to use SAS to produce both informative and aesthetically pleasing graphs. Following sections illustrate first, dataset used, second, graph and third, SAS code used to produce the graph. Graphs In SAS B [email protected] Linked Wordpress Photowave Page 1
Transcript
Page 1: September 2015 Common Graphs In SAS · 2015. 9. 29. · September 2015 Common Graphs In SAS by Sudip Shrestha High quality graphs can be produced using vari-ous graphical procedures

September 2015

Common Graphs In SASby Sudip Shrestha

High quality graphs canbe produced using vari-ous graphical proceduresin SAS. This documentfocuses on using pro-cedures like SGPLOT,SGPANEL, SGSCAT-TER, TEMPLATEand SGRENDER togenerate high qualitygraphs in SAS (SAS9.3 was used). Varietyof graphs including boxplots, scatter plots, barcharts (horizontal andvertical), histograms andtime series plots can beproduced using SGPLOTprocedure. Similarly,charts by groups can becreated using SGPANELprocedure. This docu-ment also illustrates howto customize parametersin the graph such astitle, y-axis, x-axis, colorof graph, font size andso on. Along with thegraph types I have alsodocumented the data

used to create those graphs. Observing the structure of data presented here helps to understand organize yourown data to produce subsequent charts. I have also provided some examples of using different ODS STYLE andEXPORTING or SAVING graphs in different format including PDF, JPG and PNG. The main purpose here is toknow how to use SAS to produce both informative and aesthetically pleasing graphs. Following sections illustratefirst, dataset used, second, graph and third, SAS code used to produce the graph.

Graphs In SAS

B [email protected] Linked Wordpress Photowave Page 1

Page 2: September 2015 Common Graphs In SAS · 2015. 9. 29. · September 2015 Common Graphs In SAS by Sudip Shrestha High quality graphs can be produced using vari-ous graphical procedures

Plots Covered

• Histogram, QQ-plot, Bar chart, Scatter plot, Time series plot , Box Plot

Reading Data - NEWData ”NEW” created below was used to produce various plots from first Figure below to Figure 27 and Figures

33-35. This data was obtained from Zillow website (Zillow). It contains Zillow Home Value (ZHV) estimate in USDand Median Sale Value (MSL) in USD by region (North east and South) and by selected states as of September 22,2015.

DATA NEW;INPUT State $ Bedrooms ZHV MSL Region $ ;DATALINES;CT 2 167500 182550 NorthEastMA 2 260100 265775 NorthEastNY 2 122700 . NorthEastPA 2 119100 137650 NorthEastMD 2 179700 203975 NorthEastFL 2 127300 138435 SouthGA 2 96300 140050 SouthNC 2 97700 126200 SouthTN 2 91800 . SouthCT 3 231700 247500 NorthEastMA 3 322500 290000 NorthEastNY 3 143100 . NorthEastPA 3 149200 174575 NorthEastMD 3 232400 254635 NorthEastFL 3 177600 195390 SouthGA 3 129900 158180 SouthNC 3 143400 165750 SouthTN 3 136000 . SouthCT 4 354400 407050 NorthEastMA 4 459600 460350 NorthEastNY 4 226700 . NorthEastPA 4 274900 317750 NorthEastMD 4 356800 355625 NorthEastFL 4 275300 292915 SouthGA 4 235600 268215 SouthNC 4 257000 282700 SouthTN 4 236000 . SouthCT 5 564800 645235 NorthEastMA 5 651400 610500 NorthEastNY 5 332000 . NorthEastPA 5 282800 369120 NorthEastMD 5 485900 450015 NorthEastFL 5 431200 429550 SouthGA 5 362400 375750 SouthNC 5 323900 388800 SouthTN 5 354100 . South

;RUN;

PROC PRINT DATA=NEW(OBS=10);RUN;

Graphs In SAS

B [email protected] Linked Wordpress Photowave Page 2

Page 3: September 2015 Common Graphs In SAS · 2015. 9. 29. · September 2015 Common Graphs In SAS by Sudip Shrestha High quality graphs can be produced using vari-ous graphical procedures

Q-Q Plot using UNIVARIATE

ODS SELECT QQPlot ; ∗ Se l e c t i n g QQPlot from Univar iate output ∗ ;PROC UNIVARIATE DATA=NEW NORMAL;VAR ZHV;QQPLOT ZHV / NORMAL(MU=es t SIGMA=es t COLOR=red ) ;TITLE1 F=”Times ” H=1 C=Black ”Fig0 . QQ Plot Example ”;TITLE2 F=”Times ” ITALIC H=0.8 C=Black ”(QQ Plot o f Z i l l ow Home Value Estimate (USD) ) ”;RUN;

Histogram

PROC SGPLOT DATA=NEW;HISTOGRAM ZHV/ FILL FILLATTRS=(COLOR=green )OUTLINE SCALE=PERCENT SHOWBINS TRANSPARENCY=0.5 ;DENSITY ZHV/TYPE=NORMAL LINEATTRS=(Color=blue PATTERN=ShortDash THICKNESS=2);DENSITY ZHV/ TYPE=KERNEL LINEATTRS=(Color=red PATTERN=Dash THICKNESS=2);XAXIS LABEL=”Zi l l ow Home Value Estimate (USD) ”;keylegend / l o c a t i on=in s i d e po s i t i on=topr i gh t ;TITLE1 F=”Times ” H=1 ”Fig1 . Histogram With Various Options Example ”;TITLE2 F=”Times ” H=0.8 ITALIC C=Black ”( Histogram of Z i l l ow Home Value Estimate ) ”;RUN;

Graphs In SAS

B [email protected] Linked Wordpress Photowave Page 3

Page 4: September 2015 Common Graphs In SAS · 2015. 9. 29. · September 2015 Common Graphs In SAS by Sudip Shrestha High quality graphs can be produced using vari-ous graphical procedures

Bar ChartBasic Vertical Bar Chart

PROC SGPLOT DATA=NEW;VBAR Bedrooms/ RESPONSE=ZHV STAT=MEAN;TITLE1 F=”Times ” H=1 ”Fig2 . Basic Ve r t i c a l Bar Chart ”;TITLE2 F=”Times ” H=0.8 ITALIC C=Black ”( Z i l l ow Home Value Estimate By Bedrooms ) ”;RUN;

Vertical Bar Chart with Various Options

PROC SGPLOT DATA=NEW;VBAR Bedrooms/ RESPONSE=ZHV STAT=MEAN DATALABEL OUTLINE BARWIDTH=0.8 FILL OUTLINE GROUP=Bedrooms TRANSPARENCY=0.3DATALABELATTRS=(COLOR=red FAMILY=Ar ia l SIZE=10 STYLE=ITALIC WEIGHT=BOLD) DATALABELPOS=DATA DATASKIN=SHEEN;YAXIS LABEL=”Zi l l ow Home Value Estimate (USD) ”;XAXIS LABEL=”Number o f Bedrooms ”;TITLE1 F=”Times ” H=1 ”Fig3 . Ve r t i c a l Bar Chart With D i f f e r e n t Colors And Att r ibute s ”;TITLE2 F=”Times ” H=0.8 ITALIC C=Black ”(Avg . Z i l l ow Home Value Estimate By Bedrooms ) ”;RUN;

Graphs In SAS

B [email protected] Linked Wordpress Photowave Page 4

Page 5: September 2015 Common Graphs In SAS · 2015. 9. 29. · September 2015 Common Graphs In SAS by Sudip Shrestha High quality graphs can be produced using vari-ous graphical procedures

PROC SGPLOT DATA=NEW;VBAR Bedrooms/ RESPONSE=ZHV STAT=MEAN DATALABEL OUTLINE BARWIDTH=0.8 FILL OUTLINE GROUP=Bedrooms TRANSPARENCY=0.3DATALABELATTRS=(COLOR=red FAMILY=Ar ia l SIZE=10 STYLE=ITALIC WEIGHT=BOLD) DATALABELPOS=DATA DATASKIN=SHEEN;YAXIS GRID;XAXIS LABEL=”Number o f Bedrooms ”;TITLE1 F=”Times ” H=1 ”Fig4 . Ve r t i c a l Bar Chart With Grid Lines on Y−ax i s ”;TITLE2 F=”Times ” H=0.8 ITALIC C=Black ”(Avg . Z i l l ow Home Value Estimate By Bedrooms ) ”; RUN;

Vertical Bar Chart with Error Bar

PROC SGPLOT DATA=NEW;VBAR Bedrooms/ RESPONSE=ZHV STAT=MEAN LIMITSTAT=stddev LIMITS=Upper ;YAXIS LABEL=”Average Z i l l ow Home Value Estimate (USD) ”;TITLE1 F=”Times ” H=1 ”Fig5 . Ve r t i c a l Bar Chart With Error Bars ”;TITLE2 F=”Times ” H=0.8 ITALIC C=Black ”(Avg . Z i l l ow Home Value Estimate By Bedrooms ) ”;RUN;

Graphs In SAS

B [email protected] Linked Wordpress Photowave Page 5

Page 6: September 2015 Common Graphs In SAS · 2015. 9. 29. · September 2015 Common Graphs In SAS by Sudip Shrestha High quality graphs can be produced using vari-ous graphical procedures

Horizontal Bar Chart

PROC SGPLOT DATA=NEW;HBAR Bedrooms/ RESPONSE=ZHV STAT=MEAN OUTLINE BARWIDTH=0.8 FILL OUTLINE FILLATTRS=(COLOR=l i g h t b l u e )DATALABEL DATALABELATTRS=(COLOR=red FAMILY=Ar ia l SIZE=10 STYLE=ITALIC WEIGHT=BOLD) ;YAXIS LABEL=”Number o f Bedrooms ”;XAXIS LABEL=”Average Z i l l ow Home Value Estimate (USD) ”;TITLE1 F=”Times ” H=1 ”Fig6 . Hor i zonta l Bar Chart ”;TITLE2 F=”Times ” H=0.8 ITALIC C=Black ”(Avg . Z i l l ow Home Value Estimate By Bedrooms ) ”;RUN;

Vertical Stacked Bar Chart

PROC SGPLOT DATA=NEW;VBAR Bedrooms/ RESPONSE=ZHV GROUP=Region STAT=MEANdata l abe l d a t a l a b e l a t t r s=(weight=bold ) ;YAXIS LABEL=’Average Z i l l ow Home Value Estimate (USD) ’ ;XAXIS DISPLAY =(no labe l ) ;TITLE1 F=”Times ” H=1 ”Fig7 . Ve r t i c a l Stacked Bar Chart ”;TITLE2 F=”Times ” H=0.8 ITALIC C=Black ”(Avg . Z i l l ow Home Value Estimate By Regions and Bedrooms ) ”;RUN;

Graphs In SAS

B [email protected] Linked Wordpress Photowave Page 6

Page 7: September 2015 Common Graphs In SAS · 2015. 9. 29. · September 2015 Common Graphs In SAS by Sudip Shrestha High quality graphs can be produced using vari-ous graphical procedures

Horizontal Stacked Bar Chart

PROC SGPLOT DATA=NEW;HBAR Bedrooms/ RESPONSE=ZHV GROUP=Region STAT=MEANdata l abe l d a t a l a b e l a t t r s=(weight=bold ) ;YAXIS LABEL=’Number o f Bedrooms ’ ;XAXIS DISPLAY =(no labe l ) ;TITLE1 F=”Times ” H=1 ”Fig8 . Hor i zonta l Stacked Bar Chart ”;TITLE2 F=”Times ” H=0.8 ITALIC C=Black ”(Avg . Z i l l ow Home Value Estimate By Bedrooms and Regions ) ”;RUN;

Side by Side Vertical Bar Chart

PROC SGPLOT DATA=NEW;VBAR Bedrooms / RESPONSE=ZHV DATALABEL GROUP=Region GROUPDISPLAY=c l u s t e r STAT=MEAN

DATASKIN=g l o s s ;YAXIS LABEL=”Average Z i l l ow Home Value Estimate (USD) ”;XAXIS DISPLAY=(no labe l ) ;TITLE1 F=”Times ” H=1 ”Fig9 . Side by Side Ve r t i c a l Bar Chart ”;TITLE2 F=”Times ” H=0.8 ITALIC C=Black ”(Avg . Z i l l ow Home Value Estimate By Bedrooms and Regions ) ”;RUN;

Graphs In SAS

B [email protected] Linked Wordpress Photowave Page 7

Page 8: September 2015 Common Graphs In SAS · 2015. 9. 29. · September 2015 Common Graphs In SAS by Sudip Shrestha High quality graphs can be produced using vari-ous graphical procedures

Side by Side Horizontal Bar Chart

PROC SGPLOT DATA=NEW;HBAR Bedrooms / RESPONSE=ZHV DATALABEL GROUP=Region GROUPDISPLAY=c l u s t e r STAT=MEAN

DATASKIN=g l o s s ;XAXIS LABEL=”Average Z i l l ow Home Value Estimate (USD) ”;YAXIS LABEL=”Number o f Bedrooms ”;TITLE1 F=”Times ” H=1 ”Fig10 . Side by Side Hor i zonta l Bar Chart ”;TITLE2 F=”Times ” H=0.8 ITALIC C=Black ”(Avg . Z i l l ow Home Value Estimate By Bedrooms and Regions ) ”;RUN;

Overlayed Vertical Bar Chart

PROC SGPLOT DATA=NEW;VBAR Bedrooms/RESPONSE=ZHV STAT=MEANDATALABEL DATALABELATTRS=(COLOR=black FAMILY=Ar ia l SIZE=10 STYLE=ITALIC WEIGHT=BOLD) DATALABELPOS=DATA DATASKIN=SHEEN;VBAR Bedrooms/ RESPONSE=MSL STAT=MEANDATALABEL DATALABELATTRS=(COLOR=black FAMILY=Ar ia l SIZE=10 STYLE=ITALIC WEIGHT=BOLD) DATALABELPOS=DATA DATASKIN=SHEENBARWIDTH=0.5 TRANSPARENCY=0.2;YAXIS LABEL=”Mean value (USD) ”;XAXIS DISPLAY=(no labe l ) ;TITLE1 F=”Times ” H=1 ”Fig11 . Overlayed Ve r t i c a l Bar Chart ”;TITLE2 F=”Times ” H=0.8 ITALIC C=Black ”(Avg . Z i l l ow Home Value Estimate By Bedrooms and Regions ) ”;RUN;

Graphs In SAS

B [email protected] Linked Wordpress Photowave Page 8

Page 9: September 2015 Common Graphs In SAS · 2015. 9. 29. · September 2015 Common Graphs In SAS by Sudip Shrestha High quality graphs can be produced using vari-ous graphical procedures

Box PlotBasic Vertical Box Plot

PROC SGPLOT DATA=NEW;VBOX ZHV;TITLE1 F=”Times ” H=1 ”Fig12 . Basic Ve r t i c a l Box Plot ”;TITLE2 F=”Times ” H=0.8 ITALIC C=Black ”(Box Plot o f Z i l l ow Home Value Estimate (USD) ) ”;RUN;

Vertical Box Plot with Better Appearance

PROC SGPLOT DATA=NEW;VBOX ZHV/BOXWIDTH= 0.2 CAPSHAPE=Bracket FILLATRRS=(COLOR=l i gh t g r e en ) MEANATTRS=(COLOR=black SIZE=8 SYMBOL=SquareF i l l ed )MEDIANATTRS=(COLOR=black PATTERN=Dash THICKNESS=1) WHISKERATTRS=(COLOR=red PATTERN=Dash ) ;YAXIS LABEL=’ Z i l l ow Home Value Estimate ( d o l l a r ) ’ ;TITLE1 F=”Times ” H=1 ”Fig13 . Ve r t i c a l Box Plot With Better Appearance ”;TITLE2 F=”Times ” H=0.8 ITALIC C=Black ”(Box Plot o f Z i l l ow Home Value Estimate (USD) ) ”;RUN;

Graphs In SAS

B [email protected] Linked Wordpress Photowave Page 9

Page 10: September 2015 Common Graphs In SAS · 2015. 9. 29. · September 2015 Common Graphs In SAS by Sudip Shrestha High quality graphs can be produced using vari-ous graphical procedures

Horizontal Box Plot

PROC SGPLOT DATA=NEW;HBOX ZHV/BOXWIDTH= 0.2 CAPSHAPE=Bracket FILLATRRS=(COLOR=l i gh t g r e en ) MEANATTRS=(COLOR=black SIZE=8 SYMBOL=SquareF i l l ed )MEDIANATTRS=(COLOR=black PATTERN=Dash THICKNESS=1) WHISKERATTRS=(COLOR=red PATTERN=Dash ) ;XAXIS LABEL=’ Z i l l ow Home Value Estimate ( d o l l a r ) ’ ;TITLE1 F=”Times ” H=1 ”Fig14 . Hor i zonta l Box Plot With Better Appearance ”;TITLE2 F=”Times ” H=0.8 ITALIC C=Black ”(Box Plot o f Z i l l ow Home Value Estimate (USD) ) ”;RUN;

Vertical Box Plot by Categories

PROC SGPLOT DATA=NEW;VBOX ZHV/CATEGORY=Region CAPSHAPE=Bracket FILLATRRS=(COLOR=l i gh t g r e en ) MEANATTRS=(COLOR=black SIZE=8 SYMBOL=SquareF i l l ed )MEDIANATTRS=(COLOR=black PATTERN=Dash THICKNESS=1) WHISKERATTRS=(COLOR=red PATTERN=Dash ) ;YAXIS LABEL=’ Z i l l ow Home Value Estimate ( d o l l a r ) ’ ;TITLE1 F=”Times ” H=1 ”Fig15 . Ve r t i c a l Box Plot By Categor i e s ”;TITLE2 F=”Times ” H=0.8 ITALIC C=Black ”(Box Plot o f Z i l l ow Home Value Estimate (USD) By Region ) ”;RUN;

Graphs In SAS

B [email protected] Linked Wordpress Photowave Page 10

Page 11: September 2015 Common Graphs In SAS · 2015. 9. 29. · September 2015 Common Graphs In SAS by Sudip Shrestha High quality graphs can be produced using vari-ous graphical procedures

Horizontal Box Plot by Categories

PROC SGPLOT DATA=NEW;HBOX ZHV/CATEGORY=Region CAPSHAPE=Bracket FILLATRRS=(COLOR=l i gh t g r e en ) MEANATTRS=(COLOR=black SIZE=8 SYMBOL=SquareF i l l ed )MEDIANATTRS=(COLOR=black PATTERN=Dash THICKNESS=1) WHISKERATTRS=(COLOR=red PATTERN=Dash ) ;XAXIS LABEL=’ Z i l l ow Home Value Estimate ( d o l l a r ) ’ ;TITLE1 F=”Times ” H=1 ”Fig16 . Hor i zonta l Box Plot By Categor i e s ”;TITLE2 F=”Times ” H=0.8 ITALIC C=Black ”(Box Plot o f Z i l l ow Home Value Estimate (USD) By Region ) ”;RUN;

Box Plot with Reference Line

PROC SGPLOT DATA=NEW;REFLINE 300000/ AXIS=Y LABEL= ’300000 ’ ;VBOX ZHV/CATEGORY=Region CAPSHAPE=Bracket FILLATRRS=(COLOR=l i gh t g r e en ) MEANATTRS=(COLOR=black SIZE=8 SYMBOL=SquareF i l l ed )MEDIANATTRS=(COLOR=black PATTERN=Dash THICKNESS=1) WHISKERATTRS=(COLOR=red PATTERN=Dash ) ;YAXIS LABEL=’ Z i l l ow Home Value Estimate ( d o l l a r ) ’ ;TITLE1 F=”Times ” H=1 ”Fig17 . Ve r t i c a l Box Plot By Categor i e s and Reference Line ”;TITLE2 F=”Times ” H=0.8 ITALIC C=Black ”(Box Plot o f Z i l l ow Home Value Estimate (USD) By Region ) ”;RUN;

Graphs In SAS

B [email protected] Linked Wordpress Photowave Page 11

Page 12: September 2015 Common Graphs In SAS · 2015. 9. 29. · September 2015 Common Graphs In SAS by Sudip Shrestha High quality graphs can be produced using vari-ous graphical procedures

Scatter PlotBasic Scatter Plot

PROC SGPLOT DATA=NEW;SCATTER X=ZHV Y=MSL;TITLE1 F=”Times ” H=1 ”Fig18 . Basic Sca t t e r p lo t ”;TITLE2 F=”Times ” H=0.8 ITALIC C=Black ”( Scat t e r Plot o f Median Sale Value Vs . Z i l l ow Home Value ) ”;RUN;

Scatter Plot with Data Labels

PROC SGPLOT DATA=NEW;SCATTER X=ZHV Y=MSL/ DATALABEL=State markerattrs=(SYMBOL=C i r c l e F i l l e d COLOR=blue SIZE=7);YAXIS LABEL=”Median Sale Value (USD) ”;XAXIS LABEL=”Zi l l ow Home Value Estimate (USD) ”;TITLE1 F=”Times ” H=1 ”Fig19 . Sca t t e r p lo t With Data Labels ”;TITLE2 F=”Times ” H=0.8 ITALIC C=Black ”( Scat t e r Plot o f Median Sale Value Vs . Z i l l ow Home Value ) ”;RUN;

Graphs In SAS

B [email protected] Linked Wordpress Photowave Page 12

Page 13: September 2015 Common Graphs In SAS · 2015. 9. 29. · September 2015 Common Graphs In SAS by Sudip Shrestha High quality graphs can be produced using vari-ous graphical procedures

Scatter Plot by Categories

PROC SGPLOT DATA=NEW;SCATTER X=ZHV Y=MSL/ DATALABEL=State GROUP=Region ;YAXIS LABEL=”Median Sale Value (USD) ”;XAXIS LABEL=”Zi l l ow Home Value Estimate (USD) ”;KEYLEGEND/ l o c a t i on=outs ide POSITION=r i gh t ac ro s s =1;TITLE1 F=”Times ” H=1 ”Fig20 . Sca t t e r p lo t With Categor i e s ”;TITLE2 F=”Times ” H=0.8 ITALIC C=Black ”( Scat t e r Plot o f Median Sale Value Vs . Z i l l ow Home Value By Region ) ”;RUN;

Panel PlotPanel Plot of Histograms

PROC SGPANEL DATA=NEW;PANELBY Region/ ROWS=1 COLUMNS=2 SPACING=3;HISTOGRAM ZHV/ FILL FILLATTRS=(COLOR=blue )OUTLINE SCALE=PERCENT TRANSPARENCY=0.5 ;DENSITY ZHV/TYPE=NORMAL LINEATTRS=(Color=green PATTERN=ShortDash THICKNESS=2);DENSITY ZHV/ TYPE=Kernel LINEATTRS=(Color=red PATTERN=Dash THICKNESS=2);COLAXIS LABEL=”Zi l l ow Home Value Estimate (USD) ”;TITLE1 F=”Times ” H=1 ”Fig21 . Panel Plot o f Histogram ”;TITLE2 F=”Times ” H=0.8 ITALIC C=Black ”( Histograms By Region ) ”;RUN;

Graphs In SAS

B [email protected] Linked Wordpress Photowave Page 13

Page 14: September 2015 Common Graphs In SAS · 2015. 9. 29. · September 2015 Common Graphs In SAS by Sudip Shrestha High quality graphs can be produced using vari-ous graphical procedures

Panel Box Plots

PROC SGPANEL DATA=NEW;PANELBY Region/ ROWS=1 COLUMNS=2 SPACING=3;VBOX ZHV/BOXWIDTH= 0.2 CAPSHAPE=Bracket FILLATRRS=(COLOR=gray ) MEANATTRS=(COLOR=black SIZE=8 SYMBOL=SquareF i l l ed )MEDIANATTRS=(COLOR=black PATTERN=Dash THICKNESS=1) WHISKERATTRS=(COLOR=red PATTERN=Dash ) ;ROWAXIS LABEL=”Zi l l ow Home Value Estimate (USD) ”;TITLE1 F=”Times ” H=1 ”Fig22 . Panel Ve r t i c a l Box Plot ”;TITLE2 F=”Times ” H=0.8 ITALIC C=Black ”(Box Plots By Region ) ”;RUN;

Basic Panel Scatter Plots

PROC SGPANEL data=NEW ;PANELBY Region / ROWS=1 COLUMNS=2;SCATTER X=ZHV Y=MSL/GROUP=REGION;ROWAXIS LABEL=”Medial Sa le Value (USD) ”;COLAXIS LABEL=”Zi l l ow Home Value Estimate (USD) ”;TITLE1 F=”Times ” H=1 ”Fig23 . Basic Panel Scat t e r Plot ”;TITLE2 F=”Times ” H=0.8 ITALIC C=Black ”( Scat t e r Plot o f Median Sale Value Vs . Z i l l ow Home Value By Region ) ”;RUN;

Graphs In SAS

B [email protected] Linked Wordpress Photowave Page 14

Page 15: September 2015 Common Graphs In SAS · 2015. 9. 29. · September 2015 Common Graphs In SAS by Sudip Shrestha High quality graphs can be produced using vari-ous graphical procedures

Panel Scatter Plots by Categories

PROC SGPANEL data=NEW;PANELBY Region / ROWS=1 COLUMNS=2 spac ing=3;SCATTER X=ZHV Y=MSL/DATALABEL=State GROUP=Bedrooms MARKERATTRS=(SYMBOL=C i r c l e F i l l e d SIZE=12);ROWAXIS LABEL=”Medial Sa le Value (USD) ”;COLAXIS LABEL=”Zi l l ow Home Value Estimate (USD) ”;TITLE1 F=”Times ” H=1 ”Fig24 . Panel Sca t t e r Plot By Categor i e s ”;TITLE2 F=”Times ” H=0.8 ITALIC C=Black ”( Scat t e r Plot o f Median Sale Value Vs . Z i l l ow Home Value By Region ) ”;RUN;

Panel Bar Plots

PROC SGPANEL DATA=NEW;PANELBY Region/ROWS=1 COLUMNS=2 SPACING=3;VBAR Bedrooms/ RESPONSE=ZHV DATALABEL GROUP=Region GROUPDISPLAY=c l u s t e r STAT=MEAN

DATASKIN=g l o s s ;COLAXIS LABEL=”No . o f Bedrooms” va l u ea t t r s=( s i z e =7);ROWAXIS LABEL=”Average Z i l l ow Home Value Estimate (USD)” va l u ea t t r s=( s i z e =7);TITLE1 F=”Times ” H=1 ”Fig25 . Panel Ve r t i c a l Bar Plot With Various Options ”;TITLE2 F=”Times ” H=0.8 ITALIC C=Black ”( Median Sale Value Vs . Z i l l ow Home Value By Bedrooms and Region ) ”;RUN;

Graphs In SAS

B [email protected] Linked Wordpress Photowave Page 15

Page 16: September 2015 Common Graphs In SAS · 2015. 9. 29. · September 2015 Common Graphs In SAS by Sudip Shrestha High quality graphs can be produced using vari-ous graphical procedures

Panel Vertical Bar Plots With Various Options

PROC SGPANEL DATA=NEW;PANELBY Bedrooms/SPACING=3;VBAR Bedrooms/ RESPONSE=ZHV DATALABEL GROUP=Region GROUPDISPLAY=c l u s t e r STAT=MEAN

DATASKIN=g l o s s ;COLAXIS LABEL=”No . o f Bedrooms” va l u ea t t r s=( s i z e =7);ROWAXIS LABEL=”Average Z i l l ow Home Value Estimate (USD)” va l u ea t t r s=( s i z e =7);TITLE1 F=”Times ” H=1 ”Fig26 . Panel Ve r t i c a l Bar Plot With Various Options ”;TITLE2 F=”Times ” H=0.8 ITALIC C=Black ”( Median Sale Value Vs . Z i l l ow Home Value By Bedrooms and Region ) ”;RUN;

Panel Horizontal Bar Plots With Various Options

PROC SGPANEL DATA=NEW;PANELBY Region/ROWS=1 COLUMNS=2 SPACING=3;HBAR Bedrooms/ RESPONSE=ZHV DATALABEL GROUP=Region GROUPDISPLAY=c l u s t e r STAT=MEAN

DATASKIN=g l o s s ;ROWAXIS LABEL=”No . o f Bedrooms” va l u ea t t r s=( s i z e =7);COLAXIS LABEL=”Average Z i l l ow Home Value Estimate (USD)” va l u ea t t r s=( s i z e =7);

Graphs In SAS

B [email protected] Linked Wordpress Photowave Page 16

Page 17: September 2015 Common Graphs In SAS · 2015. 9. 29. · September 2015 Common Graphs In SAS by Sudip Shrestha High quality graphs can be produced using vari-ous graphical procedures

TITLE1 F=”Times ” H=1 ”Fig27 . Panel Hor i zonta l Bar Plot With Various Options ”;TITLE2 F=”Times ” H=0.8 ITALIC C=Black ”( Median Sale Value Vs . Z i l l ow Home Value By Bedrooms and Region ) ”;RUN;

Reading in Data - NEW1NEW1 data was created in SAS using DATA STEP. The dataset NEW1 was used to produce Figures from 28-32.

DATA NEW1;INPUT Name $ Y X1 X2 $ X3 $ X4 X5 ;DATALINES;Ram 50.5 50 1 M 49.3427168 100.1378753Shyam 57 75 1 M 74.5748889 113.5496891Hari 56 .5 76 1 M 75.38768208 112.085138Rob 57.2 81 1 M 80.55908851 114.0648791Bob 59 82 1 M 81.27946349 117.7742516Jack 60 83 1 M 82.35368416 119.7807172Rita 55 .6 75 1 F 74.7954248 110.934286Gita 60 90 1 F 89.93763271 119.9752441S i ta 65 90 1 F 89.12657666 129.5902936Rima 65 80 1 F 79.16403569 129.9197289Jack ie 62 85 1 F 84.13810177 123.8520757Jina 45 102 1 F 101.0831191 89.34791501Rima 65 115 1 F 114.4839391 129.2620261Rina 66 116 1 F 115.6203107 131.2301331Badri 70 115 2 M 114.2848933 139.5138688Pangeni 70 .5 95 2 M 94.82769505 140.6473497Ramu 70.5 100 2 M 99.24356677 140.5594035Biku 65 .6 90 .5 2 M 89.56955241 131.1998039Niket 80 .5 130 2 M 129.4034546 160.6835325Nik 77 .2 90 2 M 89.81782705 153.9586373Niki 40 .5 55 .5 2 F 54.70818551 80.49470512Tini 55 .5 75 2 F 74.52304276 110.9069717t ina 55 75 2 F 74.64672523 109.8121299Mina 57 60 2 F 59.7586824 113.3529203Shima 58 68 2 F 67.40049309 115.3079217Dina 67 70 .5 2 F 70.29105429 133.0246685Hima 66 77 .5 2 F 77.4993716 131.085173Kale 75 80 .5 3 M 79.66415272 149.6352208Gore 65 68 .5 3 M 68.08185709 129.2160671Sadip 89 100.5 3 M 99.68548021 177.1263092Lagech 41 56 .5 3 M 56.07485777 81.72962152Bin 52 44 .5 3 M 43.8472248 103.5778251Meng 80 116.5 3 M 116.1980255 159.8814597Jhumma 38 45 3 F 44.4367923 75.90674303Angel ica 25 18 3 F 17.90972769 49.92113172Lisa 30 45 3 F 44.67074059 59.97366636Kal i 29 .5 45 3 F 44.00936763 58.04313572Se t i 24 28 3 F 27.78297263 47.56982616Gori 60 29 3 F 28.99364093 119.2156992;RUN;

Graphs In SAS

B [email protected] Linked Wordpress Photowave Page 17

Page 18: September 2015 Common Graphs In SAS · 2015. 9. 29. · September 2015 Common Graphs In SAS by Sudip Shrestha High quality graphs can be produced using vari-ous graphical procedures

Scatter Plots Using SGSCATTERScatter Plot Using PLOT Statement in SGSCATTER

PROC SGSCATTER DATA=NEW1;PLOT Y∗(X1 X4 X5)/ ROWS=1 COLUMNS=3;TITLE1 F=”Times ” H=1 ”Fig28 . Sca t t e r Plot Using PLOT Statement in SGSCATTER”;TITLE2 F=”Times ” H=0.8 ITALIC C=Black ”(Y vs . X1 , X4 and X5 ) ”;RUN;

Scatter Plot Using COMPARE Statement in SGSCATTER

PROC SGSCATTER DATA=NEW1;COMPARE Y=Y X=(X1 X4 X5 ) ;TITLE1 F=”Times ” H=1 ”Fig29 . Sca t t e r Plot Using COMPARE Statement in SGSCATTER”;TITLE2 F=”Times ” H=0.8 ITALIC C=Black ”(Y vs . X1 , X4 and X5 ) ”;run ;

Graphs In SAS

B [email protected] Linked Wordpress Photowave Page 18

Page 19: September 2015 Common Graphs In SAS · 2015. 9. 29. · September 2015 Common Graphs In SAS by Sudip Shrestha High quality graphs can be produced using vari-ous graphical procedures

Scatter Plot Using MATRIX Statement in SGSCATTER

PROC SGSCATTER DATA=NEW1;MATRIX Y X1 X4 X5 ;TITLE1 F=”Times ” H=1 ”Fig30 . Sca t t e r Plot Using MATRIX Statement in SGSCATTER”;TITLE2 F=”Times ” H=0.8 ITALIC C=Black ”(Y vs . X1 , X4 and X5 ) ”;RUN;

Scatter Plot Using PLOT Statement by Group in SGSCATTER (With Data Label)

PROC SGSCATTER DATA=NEW1;PLOT Y∗(X1 X4 X5)/DATALABEL=Name GROUP=X3 ROWS=1 COLUMNS=3;TITLE1 F=”Times ” H=1 ”Fig31 . Sca t t e r Plot Using PLOT Statement By Group in SGSCATTER”;TITLE2 F=”Times ” H=0.8 ITALIC C=Black ”(Y vs . X1 , X4 and X5 By Gender ) ”;RUN;

Graphs In SAS

B [email protected] Linked Wordpress Photowave Page 19

Page 20: September 2015 Common Graphs In SAS · 2015. 9. 29. · September 2015 Common Graphs In SAS by Sudip Shrestha High quality graphs can be produced using vari-ous graphical procedures

Scatter Plot Using MATRIX Statement by Group in SGSCATTER

PROC SGSCATTER DATA=NEW1;MATRIX Y X1 X4 X5/GROUP=X3 DIAGONAL=(histogram KERNEL) ;TITLE1 F=”Times ” H=1 ”Fig32 . Sca t t e r Plot Using MATRIX Statement By Group in SGSCATTER”;TITLE2 F=”Times ” H=0.8 ITALIC C=Black ”(Y vs . X1 , X4 and X5 By Gender ) ”;RUN;

Graphs In SAS

B [email protected] Linked Wordpress Photowave Page 20

Page 21: September 2015 Common Graphs In SAS · 2015. 9. 29. · September 2015 Common Graphs In SAS by Sudip Shrestha High quality graphs can be produced using vari-ous graphical procedures

Plots Using TEMPLATE and SGRENDERPanel Plots

PROC TEMPLATE;DEFINE STATGRAPH Panelp lot ;BEGINGRAPH;ENTRYTITLE ”Fig33 . Panel Display Using SGRENDER”;

LAYOUT LATTICE / ROWS= 2 COLUMNS= 2 ROWGUTTER= 8 COLUMNGUTTER=8;LAYOUT OVERLAY;SCATTERPLOT Y = MSL X = ZHV;REGRESSIONPLOT Y = MSL X = ZHV;ENDLAYOUT;

LAYOUT OVERLAY / XAXISOPTS = (LABEL= ’MSL’ ) ;HISTOGRAM MSL;ENDLAYOUT;

LAYOUT OVERLAY / YAXISOPTS = (LABEL= ’ZHV’ ) ;BOXPLOT Y = ZHV;ENDLAYOUT;

LAYOUT OVERLAY;SCATTERPLOT Y = MSL X = ZHV/ GROUP = Region NAME = ”Scat ”;DISCRETELEGEND ”Scat ” / TITLE = ’Region ’ ;ENDLAYOUT;ENDLAYOUT;

ENDGRAPH;END;TITLE1 F=”Times ” H=1 ”Fig33 . Various Plots Using TEMPLATE and SGRENDER”;TITLE2 F=”Times ” H=0.8 ITALIC C=Black ”(Y vs . X1 , X4 and X5 By Gender ) ”;RUN;

PROC SGRENDER DATA = NEW TEMPLATE = Panelp lot ;RUN;

Graphs In SAS

B [email protected] Linked Wordpress Photowave Page 21

Page 22: September 2015 Common Graphs In SAS · 2015. 9. 29. · September 2015 Common Graphs In SAS by Sudip Shrestha High quality graphs can be produced using vari-ous graphical procedures

Use of Attribute MAP to Assign Colors By Categories

proc template ;d e f i n e statgraph ClusteredBar ;begingraph ;

e n t r y t i t l e ’ Fig34 . Use o f Attr ibute MAP to Assign Colors By Categor ies ’ ;/∗ Di f i n ing Attr ibute map and a s s i gn ing a name ” c o l o r s ”∗/

d i sc re teat t rmap NAME=’ co lo r s ’ / i gno r e ca s e=true ;value ”NorthEas ” / f i l l a t t r s =( co l o r=vigb ) ;value ”South ” / f i l l a t t r s =( co l o r=purple ) ;

enddiscreteattrmap ;

/∗ Linking the a t t r i bu t e map de f ined above with the input data column Region ∗//∗ and as s i gn the name RegionColors to a t t rva r ∗/d i s c r e t e a t t r v a r ATTRVAR=RegionColors VAR=Region ATTRMAP=’ co lo r s ’ ;

/∗ Reference RegionColors in the BARCHART statement ∗//∗ Def ine l a b e l o f Y ax i s and X ax i s o f Barchart ∗/ ;

layout over lay /YAXISOPTS = (LABEL= ’ Z i l l ow Home Value Estimate (USD) ’ ) XAXISOPTS = (LABEL= ’No . o f Bedrooms ’ ) ;barchart x=Bedrooms y=ZHV / group=RegionColors groupdisp lay=c l u s t e r STAT=MEAN name=’Region ’

datask in=pressed ba r l abe l=true ;

d i s c r e t e l e g end ’ Region ’ ;endlayout ;

endgraph ;end ;

run ;

proc sgrender data=NEW template=ClusteredBar ;run ;

Graphs In SAS

B [email protected] Linked Wordpress Photowave Page 22

Page 23: September 2015 Common Graphs In SAS · 2015. 9. 29. · September 2015 Common Graphs In SAS by Sudip Shrestha High quality graphs can be produced using vari-ous graphical procedures

Bar Chart with Various Patterns

proc template ;d e f i n e statgraph PatternGraph ;begingraph ;

e n t r y t i t l e ’ Fig35 . Barchart With Various Patterns ’ ;layout over lay /YAXISOPTS = (LABEL= ’ Z i l l ow Home Value Estimate (USD) ’ ) XAXISOPTS = (LABEL= ’No . o f Bedrooms ’ ) ;

barchart x=Bedrooms y=ZHV / group=Bedrooms STAT=MEAN di sp l ay=( f i l l p a t t e r n f i l l o u t l i n e ) datask in=g l o s s ;endlayout ;

endgraph ;end ;

/∗ F i l l pat te rns are de f ined us ing the FILLPATTERN s t y l e element a t t r i bu t e . ∗/de f i n e s t y l e s t y l e s . mypatterns ;parent=s t y l e s . l i s t i n g ;

s t y l e GraphData1 from GraphData1 /f i l l p a t t e r n = ”L3 ”;

s t y l e GraphData2 from GraphData2 /f i l l p a t t e r n = ”X3”;

s t y l e GraphData3 from GraphData3 /f i l l p a t t e r n = ”R3 ”;

s t y l e GraphData4 from GraphData4 /f i l l p a t t e r n = ”L5 ”;

end ;run ;

ods html s t y l e=mypatterns ;ods graph ic s /imagename=’Fig35 ’ imagefmt=jpg ; ∗∗ or jpeg ;proc sgrender data=NEW template=PatternGraph ;run ;

Graphs In SAS

B [email protected] Linked Wordpress Photowave Page 23

Page 24: September 2015 Common Graphs In SAS · 2015. 9. 29. · September 2015 Common Graphs In SAS by Sudip Shrestha High quality graphs can be produced using vari-ous graphical procedures

Time Series PlotsReading in Data- TIMESEREIS (Multiple Response Variables- Ungrouped Data)TIMESERIES data was created with time variable and several continuous variables. This data was also obtained

from Zillow website. This data includes Zillow home value estimate of 2 bedrooms house in Metro Area (Atlanta,Boston and New York) from January 2013 to August 2015. Figures 36-37 were created using the dataset TIME-SERIES.

DATA TIMESERIES ;INPUT year MMYY $ US Atl Metro Bos Metro Ny Metro ;DATALINES;2013 Jan−13 118100 78300 244400 2634002013 Feb−13 118300 78400 245500 2634002013 Mar−13 118900 78700 246800 2636002013 Apr−13 119800 79100 248200 2640002013 May−13 120900 79800 250100 2647002013 Jun−13 122000 81200 252500 2658002013 Jul−13 123200 83200 255100 2672002013 Aug−13 124400 85100 257700 2688002013 Sep−13 125400 86800 260400 2705002013 Oct−13 126400 88300 262500 2722002013 Nov−13 127300 90000 264300 2737002013 Dec−13 128300 91400 266400 2751002014 Jan−14 129200 92400 268300 2763002014 Feb−14 129900 93400 269200 2772002014 Mar−14 130900 94800 269800 2785002014 Apr−14 132200 96800 271200 2815002014 May−14 133100 98500 272900 2842002014 Jun−14 133700 99600 274000 2853002014 Jul−14 134100 100500 274600 2861002014 Aug−14 134400 101800 274800 2866002014 Sep−14 135100 102900 275200 2860002014 Oct−14 135600 103700 275900 2857002014 Nov−14 136000 104500 276500 2862002014 Dec−14 136300 105400 276800 2865002015 Jan−15 136600 106000 277700 2863002015 Feb−15 137200 106500 280800 2871002015 Mar−15 137900 107100 284700 2886002015 Apr−15 138500 107700 287400 2892002015 May−15 139100 108300 288600 2889002015 Jun−15 139600 109000 289200 2887002015 Jul−15 140100 109800 289900 2889002015 Aug−15 140600 110500 290900 289400;RUN;

PROC PRINT DATA=TIMESERIES ;RUN;

Time Series Plots of Multiple Response Variables

PROC SGPLOT DATA = TIMESERIES ;XAXIS TYPE = DISCRETE;SERIES X = MMYY Y = US/ MARKERS MARKERATTRS=(SYMBOL=C i r c l e F i l l e d COLOR=red SIZE=7)LEGENDLABEL=”National ” LINEATTRS=(THICKNESS=2 PATTERN=so l i d COLOR=red ) ;SERIES X = MMYY Y= Atl Metro / MARKERS MARKERATTRS=(SYMBOL=SquareF i l l ed COLOR=black SIZE=7)LEGENDLABEL=”Atlanta ” LINEATTRS=(THICKNESS=2 PATTERN=so l i d COLOR=black ) ;SERIES X = MMYY Y= Bos Metro / MARKERS MARKERATTRS=(SYMBOL=DiamondFilled COLOR=green SIZE=7)LEGENDLABEL=”Boston ” LINEATTRS=(THICKNESS=2 PATTERN=so l i d COLOR=green ) ;SERIES X = MMYY Y= Ny Metro / MARKERS MARKERATTRS=(SYMBOL=Star COLOR=blue SIZE=7)LEGENDLABEL=”New York” LINEATTRS=(THICKNESS=2 PATTERN=so l i d COLOR=blue ) ;YAXIS LABEL=”Zi l l ow Home Value Estimate o f 2Bd House (USD)” GRID;XAXIS LABEL=”Time ”;KEYLEGEND/ LOCATION= OUTSIDE POSITION = BOTTOM;TITLE1 F=”Times ” H=1 ”Fig36 . Mult ip le Response Var iab l e s ( S e r i e s ) Time S e r i e s Plots ”;TITLE2 F=”Times ” H=0.8 ITALIC C=Black

Graphs In SAS

B [email protected] Linked Wordpress Photowave Page 24

Page 25: September 2015 Common Graphs In SAS · 2015. 9. 29. · September 2015 Common Graphs In SAS by Sudip Shrestha High quality graphs can be produced using vari-ous graphical procedures

”( Z i l l ow Home Value Estimate o f 2Bd House in Metro Area From Jan13 to Aug15 ) ”;RUN;

Time Series Plots of Multiple Response Variables Using TEMPLATE and SGRENDER

proc template ; d e f i n e statgraph UngroupedSeries ;begingraph ;e n t r y t i t l e ”Fig37 . Overlay o f Mult ip le SERIESPLOTs Using TEMPLATE and SGRENDER”;layout over lay / xax i sopt s=(timeopts=( i n t e r v a l=quarter ) )yax i sopt s=( l a b e l=”Zi l l ow Home Value Estimate o f 2 Bedroom House (USD) ”) ;s e r i e s p l o t x=mmyy y=US / cu rve l abe l=”US” l i n e a t t r s=GraphData1 ;s e r i e s p l o t x=mmyy y=Atl Metro / cu rve l abe l=”Atl Metro ” l i n e a t t r s=GraphData2 ;s e r i e s p l o t x=mmyy y=Bos Metro / cu rve l abe l=”Bos Metro ” l i n e a t t r s=GraphData3 ;s e r i e s p l o t x=mmyy y=Ny Metro / cu rve l abe l=”Ny Metro ” l i n e a t t r s=GraphData4 ;endlayout ;endgraph ;end ; run ;proc sgrender data=TIMESERIES template=UngroupedSeries ;RUN;

Graphs In SAS

B [email protected] Linked Wordpress Photowave Page 25

Page 26: September 2015 Common Graphs In SAS · 2015. 9. 29. · September 2015 Common Graphs In SAS by Sudip Shrestha High quality graphs can be produced using vari-ous graphical procedures

Time Series Plots- Grouped DataReading in Data- GROUPEDDATAThis data is similar to TIMESERIES data created above. The only difference is that it is in long format which is

also referred as grouped data. Figures 38-39 were created using dataset GROUPEDATA.

DATA groupeddata ;INPUT Year MMYY $ Area $ ZHV;DATALINES;2013 Jan−13 US 1181002013 Feb−13 US 1183002013 Mar−13 US 1189002013 Apr−13 US 1198002013 May−13 US 1209002013 Jun−13 US 1220002013 Jul−13 US 1232002013 Aug−13 US 1244002013 Sep−13 US 1254002013 Oct−13 US 1264002013 Nov−13 US 1273002013 Dec−13 US 1283002014 Jan−14 US 1292002014 Feb−14 US 1299002014 Mar−14 US 1309002014 Apr−14 US 1322002014 May−14 US 1331002014 Jun−14 US 1337002014 Jul−14 US 1341002014 Aug−14 US 1344002014 Sep−14 US 1351002014 Oct−14 US 1356002014 Nov−14 US 1360002014 Dec−14 US 1363002015 Jan−15 US 1366002015 Feb−15 US 1372002015 Mar−15 US 1379002015 Apr−15 US 1385002015 May−15 US 1391002015 Jun−15 US 1396002015 Jul−15 US 1401002015 Aug−15 US 1406002013 Jan−13 Atl Metro 783002013 Feb−13 Atl Metro 784002013 Mar−13 Atl Metro 787002013 Apr−13 Atl Metro 791002013 May−13 Atl Metro 798002013 Jun−13 Atl Metro 812002013 Jul−13 Atl Metro 832002013 Aug−13 Atl Metro 851002013 Sep−13 Atl Metro 868002013 Oct−13 Atl Metro 883002013 Nov−13 Atl Metro 900002013 Dec−13 Atl Metro 914002014 Jan−14 Atl Metro 924002014 Feb−14 Atl Metro 934002014 Mar−14 Atl Metro 948002014 Apr−14 Atl Metro 968002014 May−14 Atl Metro 985002014 Jun−14 Atl Metro 996002014 Jul−14 Atl Metro 1005002014 Aug−14 Atl Metro 1018002014 Sep−14 Atl Metro 1029002014 Oct−14 Atl Metro 1037002014 Nov−14 Atl Metro 1045002014 Dec−14 Atl Metro 1054002015 Jan−15 Atl Metro 1060002015 Feb−15 Atl Metro 1065002015 Mar−15 Atl Metro 1071002015 Apr−15 Atl Metro 1077002015 May−15 Atl Metro 1083002015 Jun−15 Atl Metro 1090002015 Jul−15 Atl Metro 1098002015 Aug−15 Atl Metro 1105002013 Jan−13 Bos Metro 2444002013 Feb−13 Bos Metro 2455002013 Mar−13 Bos Metro 2468002013 Apr−13 Bos Metro 2482002013 May−13 Bos Metro 2501002013 Jun−13 Bos Metro 2525002013 Jul−13 Bos Metro 2551002013 Aug−13 Bos Metro 2577002013 Sep−13 Bos Metro 2604002013 Oct−13 Bos Metro 2625002013 Nov−13 Bos Metro 2643002013 Dec−13 Bos Metro 2664002014 Jan−14 Bos Metro 2683002014 Feb−14 Bos Metro 2692002014 Mar−14 Bos Metro 2698002014 Apr−14 Bos Metro 2712002014 May−14 Bos Metro 2729002014 Jun−14 Bos Metro 2740002014 Jul−14 Bos Metro 2746002014 Aug−14 Bos Metro 2748002014 Sep−14 Bos Metro 2752002014 Oct−14 Bos Metro 2759002014 Nov−14 Bos Metro 2765002014 Dec−14 Bos Metro 2768002015 Jan−15 Bos Metro 2777002015 Feb−15 Bos Metro 2808002015 Mar−15 Bos Metro 2847002015 Apr−15 Bos Metro 2874002015 May−15 Bos Metro 2886002015 Jun−15 Bos Metro 2892002015 Jul−15 Bos Metro 2899002015 Aug−15 Bos Metro 2909002013 Jan−13 Ny Metro 2634002013 Feb−13 Ny Metro 2634002013 Mar−13 Ny Metro 2636002013 Apr−13 Ny Metro 2640002013 May−13 Ny Metro 264700

Graphs In SAS

B [email protected] Linked Wordpress Photowave Page 26

Page 27: September 2015 Common Graphs In SAS · 2015. 9. 29. · September 2015 Common Graphs In SAS by Sudip Shrestha High quality graphs can be produced using vari-ous graphical procedures

2013 Jun−13 Ny Metro 2658002013 Jul−13 Ny Metro 2672002013 Aug−13 Ny Metro 2688002013 Sep−13 Ny Metro 2705002013 Oct−13 Ny Metro 2722002013 Nov−13 Ny Metro 2737002013 Dec−13 Ny Metro 2751002014 Jan−14 Ny Metro 2763002014 Feb−14 Ny Metro 2772002014 Mar−14 Ny Metro 2785002014 Apr−14 Ny Metro 2815002014 May−14 Ny Metro 2842002014 Jun−14 Ny Metro 2853002014 Jul−14 Ny Metro 2861002014 Aug−14 Ny Metro 2866002014 Sep−14 Ny Metro 2860002014 Oct−14 Ny Metro 2857002014 Nov−14 Ny Metro 2862002014 Dec−14 Ny Metro 2865002015 Jan−15 Ny Metro 2863002015 Feb−15 Ny Metro 2871002015 Mar−15 Ny Metro 2886002015 Apr−15 Ny Metro 2892002015 May−15 Ny Metro 2889002015 Jun−15 Ny Metro 2887002015 Jul−15 Ny Metro 2889002015 Aug−15 Ny Metro 289400;RUN;PROC PRINT DATA=groupeddata ; RUN;

Time Series Plots of Grouped Data Using TEMPLATE and SGRENDER

proc template ;d e f i n e statgraph groupedse r i e s ;begingraph ;e n t r y t i t l e ”Fig38 . Time S e r i e s Plot o f Grouped Data ”;en t ry foo tnoteha l i gn=l e f t ”Source : www. z i l l ow . com/home−va lues / ”;layout over lay ;s e r i e s p l o t x=MMYY y=ZHV / group=Area name=”s e r i e s ” l i n e a t t r s =( th i ckne s s =2);d i s c r e t e l e g end ” s e r i e s ”;endlayout ;endgraph ;end ;run ;

proc sgrender data=groupeddata template=groupedse r i e s ;run ;

Graphs In SAS

B [email protected] Linked Wordpress Photowave Page 27

Page 28: September 2015 Common Graphs In SAS · 2015. 9. 29. · September 2015 Common Graphs In SAS by Sudip Shrestha High quality graphs can be produced using vari-ous graphical procedures

Time Series Plots of Grouped Data with Various Colors and Styles

proc template ;d e f i n e statgraph new0 ;begingraph ;e n t r y t i t l e ”Fig39 . P lo t t ing Grouped S e i r e s with Mult ip le Color and Sty l e s ”;d i s c re teat t rmap name=”name1” / i gno r e ca s e=true ;value ”US” / markerattrs=GraphData1 ( c o l o r=red symbol=c i r c l e f i l l e d )l i n e a t t r s=GraphData1 ( c o l o r=red pattern=s o l i d ) ;value ”Atl Metr ” / markerattrs=GraphData2 ( c o l o r=green symbol=t r i a n g l e f i l l e d )l i n e a t t r s=GraphData2 ( c o l o r=green pattern=shortdash ) ;value ”Bos Metr ” / markerattrs=GraphData3 ( c o l o r=blue symbol=s q u a r e f i l l e d )l i n e a t t r s=GraphData3 ( c o l o r=blue pattern=dot ) ;value ”Ny Metro ” / markerattrs=GraphData4 ( c o l o r=black symbol=s q u a r e f i l l e d )l i n e a t t r s=GraphData4 ( c o l o r=black pattern=shortdash ) ;enddiscreteattrmap ;d i s c r e t e a t t r v a r a t t rva r=stockmarkers var=Area attrmap=”name1 ”;layout over lay /YAXISOPTS = (LABEL= ’ Z i l l ow Home Value Estimate (USD) ’ g r i dd i s p l ay=on g r i d a t t r s=( co l o r=l i gh t g r ay pattern=dot ) )XAXISOPTS = (LABEL= ’Time ’ g r i dd i s p l ay=ong r i d a t t r s=( co l o r=l i gh t g r ay pattern=dot ) ) ;s e r i e s p l o t x=mmyy y=ZHV / group=stockmarkers d i sp l ay=(markers ) name=”trends ”;d i s c r e t e l e g end ”trends ” / t i t l e =”Home Value Trends in ”;endlayout ;endgraph ;end ;run ;

proc sgrender data=groupeddata template=new0 ;run ;qu i t ;

Graphs In SAS

B [email protected] Linked Wordpress Photowave Page 28

Page 29: September 2015 Common Graphs In SAS · 2015. 9. 29. · September 2015 Common Graphs In SAS by Sudip Shrestha High quality graphs can be produced using vari-ous graphical procedures

Changing ODS STYLEAll following graphs were produced using the dataset NEW. ODS STYLE=HARVEST

ods html gpath=’C:\Your Directory Name’ s t y l e=Harvest ;ods graph ic s / r e s e t=a l limagename=’Fig40 ’ imagefmt=jpg ; ∗∗ or jpeg ;PROC SGPANEL DATA=NEW;PANELBY Region/ ROWS=1 COLUMNS=2 SPACING=3;HISTOGRAM ZHV/ FILL OUTLINE SCALE=PERCENT;DENSITY ZHV/TYPE=NORMAL ;DENSITY ZHV/ TYPE=Kernel ;COLAXIS LABEL=”Zi l l ow Home Value Estimate (USD) ”;TITLE1 F=”Times ” H=1 ”Fig40 . ODS HTML STYLE=Harvest ”;TITLE2 F=”Times ” H=0.8 ”( Histogram of Z i l l ow Home Value Estimate ) ”; RUN;

ODS STYLE=EDUCATION

ods html gpath=’C:\Your Directory Name’ s t y l e=Education ;ods graph ic s / r e s e t=a l limagename=’Fig41 ’ imagefmt=jpg ; ∗∗ or jpeg ;PROC SGPANEL DATA=NEW;PANELBY Region/ ROWS=1 COLUMNS=2 SPACING=3;HISTOGRAM ZHV/ FILL OUTLINE SCALE=PERCENT;DENSITY ZHV/TYPE=NORMAL ;DENSITY ZHV/ TYPE=Kernel ;COLAXIS LABEL=”Zi l l ow Home Value Estimate (USD) ”;TITLE1 F=”Times ” H=1 ”Fig41 . ODS HTML STYLE=Education ”;TITLE2 F=”Times ” H=0.8 ”( Histogram of Z i l l ow Home Value Estimate ) ”;RUN;

Graphs In SAS

B [email protected] Linked Wordpress Photowave Page 29

Page 30: September 2015 Common Graphs In SAS · 2015. 9. 29. · September 2015 Common Graphs In SAS by Sudip Shrestha High quality graphs can be produced using vari-ous graphical procedures

ODS STYLE=BARRETTSBLUE

ods html gpath=’C:\Your Directory Name’ s t y l e=Barrett sBlue ;ods graph ic s / r e s e t=a l limagename=’Fig42 ’ imagefmt=jpg ; ∗∗ or jpeg ;PROC SGPANEL DATA=NEW;PANELBY Region/ ROWS=1 COLUMNS=2 SPACING=3;HISTOGRAM ZHV/ FILL OUTLINE SCALE=PERCENT;DENSITY ZHV/TYPE=NORMAL ;DENSITY ZHV/ TYPE=Kernel ;COLAXIS LABEL=”Zi l l ow Home Value Estimate (USD) ”;TITLE1 F=”Times ” H=1 ”Fig42 . ODS HTML STYLE=BarrettsBlue ”;TITLE2 F=”Times ” H=0.8 ”( Histogram of Z i l l ow Home Value Estimate ) ”;RUN;

ODS STYLE=JOURNAL

ods html gpath=’C:\Your Directory Name’ s t y l e=Journal ;ods graph ic s / r e s e t=a l limagename=’Fig43 ’ imagefmt=jpg ; ∗∗ or jpeg ;PROC SGPANEL DATA=NEW;PANELBY Region/ ROWS=1 COLUMNS=2 SPACING=3;HISTOGRAM ZHV/ FILL OUTLINE SCALE=PERCENT;DENSITY ZHV/TYPE=NORMAL ;DENSITY ZHV/ TYPE=Kernel ;COLAXIS LABEL=”Zi l l ow Home Value Estimate (USD) ”;TITLE1 F=”Times ” H=1 ”Fig43 . ODS HTML STYLE=Journal ”;TITLE2 F=”Times ” H=0.8 ”( Histogram of Z i l l ow Home Value Estimate ) ”;RUN;

Graphs In SAS

B [email protected] Linked Wordpress Photowave Page 30

Page 31: September 2015 Common Graphs In SAS · 2015. 9. 29. · September 2015 Common Graphs In SAS by Sudip Shrestha High quality graphs can be produced using vari-ous graphical procedures

ODS STYLE=ANALYSIS

ods html gpath=’C:\Your Directory Name’ s t y l e=Analys i s ;ods graph ic s / r e s e t=a l limagename=’Fig44 ’ imagefmt=jpg ; ∗∗ or jpeg ;PROC SGPANEL DATA=NEW;PANELBY Region/ ROWS=1 COLUMNS=2 SPACING=3;HISTOGRAM ZHV/ FILL OUTLINE SCALE=PERCENT;DENSITY ZHV/TYPE=NORMAL ;DENSITY ZHV/ TYPE=Kernel ;COLAXIS LABEL=”Zi l l ow Home Value Estimate (USD) ”;TITLE1 F=”Times ” H=1 ”Fig44 . ODS HTML STYLE=Analys i s ”;TITLE2 F=”Times ” H=0.8 ”( Histogram of Z i l l ow Home Value Estimate ) ”;RUN;

ODS STYLE=HTMLBLUE

ods html gpath=’C:\Your Directory Name’ s t y l e=HTMLBlue ;ods graph ic s / r e s e t=a l limagename=’Fig45 ’ imagefmt=jpg ; ∗∗ or jpeg ;PROC SGPANEL DATA=NEW;PANELBY Region/ ROWS=1 COLUMNS=2 SPACING=3;HISTOGRAM ZHV/ FILL OUTLINE SCALE=PERCENT;DENSITY ZHV/TYPE=NORMAL ;DENSITY ZHV/ TYPE=Kernel ;COLAXIS LABEL=”Zi l l ow Home Value Estimate (USD) ”;TITLE1 F=”Times ” H=1 ”Fig45 . ODS HTML STYLE=HTMLBlue ”;TITLE2 F=”Times ” H=0.8 ”( Histogram of Z i l l ow Home Value Estimate ) ”;RUN;

Graphs In SAS

B [email protected] Linked Wordpress Photowave Page 31

Page 32: September 2015 Common Graphs In SAS · 2015. 9. 29. · September 2015 Common Graphs In SAS by Sudip Shrestha High quality graphs can be produced using vari-ous graphical procedures

ODS STYLE=STATISTICAL

ods html gpath=’C:\Your Directory Name’ s t y l e=S t a t i s t i c a l ;ods graph ic s / r e s e t=a l limagename=’Fig46 ’ imagefmt=jpg ; ∗∗ or jpeg ;PROC SGPANEL DATA=NEW;PANELBY Region/ ROWS=1 COLUMNS=2 SPACING=3;HISTOGRAM ZHV/ FILL OUTLINE SCALE=PERCENT;DENSITY ZHV/TYPE=NORMAL ;DENSITY ZHV/ TYPE=Kernel ;COLAXIS LABEL=”Zi l l ow Home Value Estimate (USD) ”;TITLE1 F=”Times ” H=1 ”Fig46 . ODS HTML STYLE=S t a t i s t i c a l ”;TITLE2 F=”Times ” H=0.8 ”( Histogram of Z i l l ow Home Value Estimate ) ”;RUN;

ODS STYLE=SCIENCE

ods html gpath=’C:\Your Directory Name’ s t y l e=Sc ience ;ods graph ic s / r e s e t=a l limagename=’Fig47 ’ imagefmt=jpg ; ∗∗ or jpeg ;PROC SGPANEL DATA=NEW;PANELBY Region/ ROWS=1 COLUMNS=2 SPACING=3;HISTOGRAM ZHV/ FILL OUTLINE SCALE=PERCENT;DENSITY ZHV/TYPE=NORMAL ;DENSITY ZHV/ TYPE=Kernel ;COLAXIS LABEL=”Zi l l ow Home Value Estimate (USD) ”;TITLE1 F=”Times ” H=1 ”Fig47 . ODS HTML STYLE=Sc ience ”;TITLE2 F=”Times ” H=0.8 ”( Histogram of Z i l l ow Home Value Estimate ) ”;RUN;

Graphs In SAS

B [email protected] Linked Wordpress Photowave Page 32

Page 33: September 2015 Common Graphs In SAS · 2015. 9. 29. · September 2015 Common Graphs In SAS by Sudip Shrestha High quality graphs can be produced using vari-ous graphical procedures

ODS STYLE=JOURNAL2

ods html gpath=’C:\Your Directory Name’ s t y l e=Journal2 ;ods graph ic s / r e s e t=a l limagename=’Fig48 ’ imagefmt=jpg ; ∗∗ or jpeg ;PROC SGPANEL DATA=NEW;PANELBY Region/ ROWS=1 COLUMNS=2 SPACING=3;HISTOGRAM ZHV/ FILL OUTLINE SCALE=PERCENT;DENSITY ZHV/TYPE=NORMAL ;DENSITY ZHV/ TYPE=Kernel ;COLAXIS LABEL=”Zi l l ow Home Value Estimate (USD) ”;TITLE1 F=”Times ” H=1 ”Fig48 . ODS HTML STYLE=Journal2 ”;TITLE2 F=”Times ” H=0.8 ”( Histogram of Z i l l ow Home Value Estimate ) ”;RUN;

ODS STYLE=LISTING

ods html gpath=’C:\Your Directory Name’ s t y l e=L i s t i n g ;ods graph ic s / r e s e t=a l limagename=’Fig49 ’ imagefmt=jpg ; ∗∗ or jpeg ;PROC SGPANEL DATA=NEW;PANELBY Region/ ROWS=1 COLUMNS=2 SPACING=3;HISTOGRAM ZHV/ FILL OUTLINE SCALE=PERCENT;DENSITY ZHV/TYPE=NORMAL ;DENSITY ZHV/ TYPE=Kernel ;COLAXIS LABEL=”Zi l l ow Home Value Estimate (USD) ”;TITLE1 F=”Times ” H=1 ”Fig49 . ODS HTML STYLE=L i s t i n g ”;TITLE2 F=”Times ” H=0.8 ”( Histogram of Z i l l ow Home Value Estimate ) ”;RUN;

Graphs In SAS

B [email protected] Linked Wordpress Photowave Page 33

Page 34: September 2015 Common Graphs In SAS · 2015. 9. 29. · September 2015 Common Graphs In SAS by Sudip Shrestha High quality graphs can be produced using vari-ous graphical procedures

Using Format Statement

PROC FORMAT;VALUE Bedrooms 2=”2−Bedrooms”

3=”3−Bedrooms”4=”4−Bedrooms”

5=”5−Bedrooms and more ”;VALUE $Region ”NorthEas”=”North East ”

”South”=”South ”;RUN;

TITLE1 ”Fig50 . Using Format Statement ”;PROC SGPANEL DATA=NEW;

PANELBY Region ;VBOX ZHV / CATEGORY= Bedrooms ;FORMAT Region $Region . ;FORMAT Bedrooms Bedrooms . ;

run ;

Various ODS Options and Saving Graphs in Specified DirectorySave as PNG or JPG

ods html gpath=’C:\Your Directory Path ’ s t y l e=S t a t i s t i c a l ;ods graph ic s / r e s e t=a l l width=10 in he ight=6in border=o f fimagename=’Figure Name ’ imagefmt=png ; ∗∗ or jpeg ;

SAS CODES . . . .For Example : PRCO SGPLOT DATA=DATANAME ; . . . . . . . . . ;

ODS HTML CLOSE;

Save as PDF

ODS PDF FILE=’C:\Your Directory Path\Figure name . pdf ’ s t y l e=S t a t i s t i c a l ;ODS GRAPHICS / RESET=ALL WIDTH=10 in HEIGHT=6in BORDER=OFF;

SAS CODES . . . .For Example : PRCO SGPLOT DATA=DATANAME ; . . . . . . . . . ;

ODS PDF CLOSE;

Save as RTF

ODS RTF FILE=’C:\Your Directory Path\Figure name . r t f ’ s t y l e=S t a t i s t i c a l ;ODS GRAPHICS / RESET=ALL WIDTH=10 in HEIGHT=6in BORDER=OFF;

SAS CODES . . . .For Example : PRCO SGPLOT DATA=DATANAME ; . . . . . . . . . ;

ODS RTF CLOSE;

Graphs In SAS

B [email protected] Linked Wordpress Photowave Page 34

Page 35: September 2015 Common Graphs In SAS · 2015. 9. 29. · September 2015 Common Graphs In SAS by Sudip Shrestha High quality graphs can be produced using vari-ous graphical procedures

References and Further Reading> SAS 9.3 Graph Template Language. User’s Guide.> Sanjay Matange, Dan Heath. 2013. SAS Statistical Graphics Procedures. SAS Institute Inc. SAS Global Forum.> Xiangxiang Meng. 2010. Creating High-Quality Scatter Plots: An Old Story Told by the New SGSCATTER

PROCEDURE. University of Cincinnati, Cincinnati, OH.

Graphs In SAS

B [email protected] Linked Wordpress Photowave Page 35


Recommended