data broadriver; input obsno date date8. heightMax heightMin heightMean flowMax flowMin flowMean; /* Defining a categorical variable called period: */ IF obsno LE 11 THEN period = 1; ELSE IF obsno LE 21 THEN period = 2; ELSE period = 3; cards; 1 31MAY04 4.11 3.58 3.76 2520 1640 1930 2 01JUN04 3.77 3.18 3.43 1950 1070 1429 3 02JUN04 4.95 3.64 4.3 4089 1739 2910 4 03JUN04 4.93 3.05 4.44 4050 907 3180 5 04JUN04 4.35 3.63 3.81 2920 1719 2020 6 05JUN04 3.74 3.19 3.62 1900 1080 1719 7 06JUN04 4.06 3.23 3.64 2440 1140 1760 8 07JUN04 5.15 3.25 3.83 4510 1160 2080 9 08JUN04 3.55 3.15 3.23 1600 1030 1140 10 09JUN04 4.97 3.22 4.46 4130 1120 3180 11 10JUN04 4.53 3.04 3.92 3250 895 2220 12 11JUN04 5.24 3.67 4.29 4700 1790 2870 13 12JUN04 4.49 3.12 3.74 3170 994 1910 14 13JUN04 4.88 3.53 4.6 3940 1570 3400 15 14JUN04 10.37 3.36 5.29 20100 1320 5790 16 15JUN04 5.41 3.14 4.32 5070 1019 3050 17 16JUN04 10.22 4.49 6.61 19600 3170 8740 18 17JUN04 14.93 5.2 8.03 37100 4610 13400 19 18JUN04 8.07 3.57 5.81 12700 1630 6210 20 19JUN04 7.48 4.48 5.27 10800 3160 4870 21 20JUN04 5.34 3.3 4.64 4920 1230 3570 22 21JUN04 5.55 3.32 4.72 5390 1260 3770 23 22JUN04 6.53 4.15 5.48 7910 2590 5330 24 23JUN04 12.21 4.41 6.08 26600 3030 7290 25 24JUN04 11.27 5.18 6.24 23200 4570 7480 26 25JUN04 8.23 5.17 5.98 13200 4550 6590 27 26JUN04 12.28 5.01 7.37 26800 4220 11100 28 27JUN04 14.28 5.2 8.65 34500 4610 15200 29 28JUN04 9.36 3.32 5.37 16700 1260 5590 30 29JUN04 6.52 5.26 5.63 7880 4740 5610 31 30JUN04 5.67 4.71 5.28 5679 3600 4810 ; run; title; /* One Bar Chart, with Simple Frequency Counts: */ PROC SGPLOT DATA = Broadriver; yaxis label="Count" min=2; vbar period; run; /* One Bar Chart, with FlowMax totals plotted: */ PROC SGPLOT DATA = Broadriver; yaxis label="Discharge" min=2; vbar period / response=flowMax; run; /* Charting the period mean rather than the period sum: */ PROC SGPLOT DATA = Broadriver; yaxis label="Discharge" min=2; vbar period / response=flowMax STAT=mean; run; /* Two Bar Charts at Once */ PROC SGPLOT DATA = Broadriver; yaxis label="Discharge" min=2; vbar period / response=flowMax; vbar period / response=flowMin barwidth=0.5 transparency=0.2; run; /* or .... */ PROC SGPLOT DATA = Broadriver; yaxis label="Discharge" min=2; vbar period / response=flowMin; vbar period / response=flowMax barwidth=0.5 transparency=0.2; run; /* Stacked Bar Charts with Two Categorical Variables: */ DATA Broadriver; LENGTH Flow $6; SET Broadriver; /* Creating a categorical variable called Flow */ IF FlowMean < 2000 THEN Flow = "Small"; ELSE IF FlowMean < 6000 THEN Flow = "Medium"; ELSE Flow = "Large"; run; PROC SGPLOT DATA = Broadriver; VBAR Flow / group=period; run; /* Mean Heights by Period/Flow combination */ PROC SGPLOT DATA = Broadriver; VBAR Flow / group=period response=HeightMean STAT=mean; yaxis label = 'Average Height (in feet)'; run; /* Frequency Bar Charts */ PROC SGPLOT DATA = Broadriver; VBAR period; LABEL Period="Period of Month"; run; /* Vertical Box Plot */ PROC SGPLOT DATA = Broadriver; title "Distribution of Mean Discharges"; vbox flowMean; run; /* Horizontal Box Plot */ PROC SGPLOT DATA = Broadriver; title "Distribution of Mean Discharges"; hbox flowMean; run; /* Horizontal Box Plots, Separated by category */ PROC SGPLOT DATA = Broadriver; title "Distribution of Mean Discharges by Period"; hbox flowMean / category=period; run; /* Histogram */ PROC SGPLOT DATA = Broadriver; title "Distribution of Mean Discharges"; histogram flowMean; keylegend / location=inside position=topright; run; /* Histogram with Normal Density Curve */ PROC SGPLOT DATA = Broadriver; title "Distribution of Mean Discharges"; histogram flowMean; density flowMean; keylegend / location=inside position=topright; run; /* Histogram with Normal Density Curve and Nonparametric Density Estimate */ PROC SGPLOT DATA = Broadriver; title "Distribution of Mean Discharges"; histogram flowMean; density flowMean; density flowMean / type=kernel; keylegend / location=inside position=topright; run; /***********************************************************/ /* Simple Scatter Plot of flowMean vs heightMean: */ title; PROC SGPLOT DATA = Broadriver; scatter x=heightMean y=flowMean; run; /* Scatter Plot of flowMean vs heightMean, with separate symbols for each category of "Period": */ PROC SGPLOT DATA = Broadriver; scatter x=heightMean y=flowMean / group=period; run; /* Scatter Plot of flowMean vs heightMean, with least squares regression line included: */ PROC SGPLOT DATA = Broadriver; reg x=heightMean y=flowMean; run; /* Scatter Plot of flowMean vs heightMean, with least squares QUADRATIC regression function included: */ PROC SGPLOT DATA = Broadriver; reg x=heightMean y=flowMean / degree=2; /* degree=3 would produce cubic regression function */ run; /* Scatter Plot of flowMean vs heightMean, with least squares regression line included, */ /* and also confidence limits for the mean response and prediction limits for a new response: */ PROC SGPLOT DATA = Broadriver; reg x=heightMean y=flowMean / CLM CLI; run; /* Scatter Plot of flowMean vs heightMean, with loess regression curve included: */ PROC SGPLOT DATA = Broadriver; loess x=heightMean y=flowMean; run; /* Scatter Plot of flowMean vs heightMean, with loess regression curve included, */ /* and also confidence limits for the mean response: */ PROC SGPLOT DATA = Broadriver; loess x=heightMean y=flowMean / CLM; run; /* Scatter Plot of flowMean vs heightMean, with penalized B-spline regression curve included, */ /* and also confidence limits for the mean response and prediction limits for a new response: */ PROC SGPLOT DATA = Broadriver; PBSPLINE x=heightMean y=flowMean / CLM CLI; run; /* Scatter Plot of flowMean vs heightMean, with BOTH the least squares regression line */ /* and the loess regression curve included: */ PROC SGPLOT DATA = Broadriver; reg x=heightMean y=flowMean; loess x=heightMean y=flowMean / NOMARKERS; run; /* Scatter Plot of Bivariate Data with prediction Ellipse: */ PROC SGPLOT DATA = Broadriver; title "Flow Measurements"; scatter x=flowMin y=flowMax; ellipse x=flowMin y=flowMax; keylegend / location=inside position=bottomright; run; /* Time Series Plots */ PROC SGPLOT DATA = Broadriver; series x=date y=flowMean; series x=date y=flowMin; series x=date y=flowMax; title "USGS 02161000 BROAD RIVER AT ALSTON, SC"; title2 "Figure of Discharge vs. Date"; run; /* Dot-type Plots with Standard Error Bars: */ PROC SGPLOT DATA = Broadriver; dot period / response=heightMean stat=mean limitstat=stddev numstd=1; run; /* Bar-line Charts over Time: */ PROC SGPLOT DATA = Broadriver; FORMAT date date9.; title "Height and Discharge"; vbar date / response=heightMean; vline date / response=flowMean y2axis; run; /* Scatter Plot of flowMean vs heightMean, specifying the different symbols for each category of "Period": */ ods graphics on / attrpriority=none; PROC SGPLOT DATA = Broadriver; styleattrs datasymbols=(circlefilled squarefilled starfilled); /* See p. 246 for symbol choices */ scatter x=heightMean y=flowMean / group=period markerattrs=(size=8px); run; ods graphics / reset; /* Panel Graphs with PROC SGPANEL: */ /* Scatter Plot of flowMean vs heightMean (separate panels for each category of "Period"): */ PROC FORMAT; VALUE pertype 1 = 'Early Period' 2 = 'Middle Period' 3 = 'Late Period'; run; PROC SGPANEL DATA = Broadriver; PANELBY Period / NOVARNAME SPACING=3; scatter x=heightMean y=flowMean / group=period; FORMAT Period pertype.; TITLE 'Plots of FlowMean vs. HeightMean, separately by Period'; run;