%let gpath='.'; %let dpi=200; ods html close; ods listing gpath=&gpath image_dpi=&dpi; /*--Formats for Direction and Knot groups--*/ proc format; value dir 0 = 'E' 45 = 'NE' 90 = 'N' 135 = 'NW' 180 = 'W' 225 = 'SW' 270 = 'S' 315 = 'SE' other = '' ; value Knots 1='0 Knots' 2='1-5 Knots' 3='5-10 Knots' 4='11-20 Knots' ; run; /*--Generate Wind Data--*/ data WindSpeed; label theta="Direction"; pi=constant("pi"); conv=pi/180.0; offset=22.5; keep theta total low high Knots; step=22.5; thetamax=360-step; /*--Generate values as stacked HighLow plots--*/ do theta=0 to thetamax by step; total=20+80*sin((theta+offset)*conv/2)*(1-0.3*ranuni(2)); low=0; nKnots=3; if total > 80 then nKnots=4; frac=total/nKnots; do Knots=1 to nknots; high=low+frac; output; low=high; end; end; run; /*--Create XY graph--*/ ods graphics / reset attrpriority=color width=5in height=3in imagename='Wind_XY_Highlow'; title h=10pt 'Wind data as stacked HighLow segments'; proc sgplot data=WindSpeed noborder; format knots knots.; styleattrs datacolors=(forestgreen lightgreen gold cxD00000); highlow x=theta low=low high=high / group=knots type=bar dataskin=pressed; yaxis offsetmin=0 label='Percent' grid; xaxis values=(0 to 360 by 45); run; /*--Make polygons for each Highlow bar and transform polar data to XY--*/ data WindPolar; pi=constant("pi"); conv=pi/180.0; offset=12; step=22.5; drop pi conv; retain id 0; set WindSpeed end=last; /*--Generate polygon for each HighLow plot--*/ id=id+1; t=theta-offset/2; r=low; x=r*cos(t*conv); y=r*sin(t*conv); output; t=theta+offset/2; r=low; x=r*cos(t*conv); y=r*sin(t*conv); output; t=theta+offset/2; r=high; x=r*cos(t*conv); y=r*sin(t*conv); output; t=theta-offset/2; r=high; x=r*cos(t*conv); y=r*sin(t*conv); output; /*--Generate radial axes data--*/ if last then do; call missing (x, y, r, theta, t, id); x1=0; y1=0; r1=100; r2=105; do theta=0 to 360-step by step; x2=r1*cos(theta*conv); y2=r1*sin(theta*conv); output; xl=r2*cos(theta*conv); yl=r2*sin(theta*conv); label=theta; output; end; end; run; /*--Define circular grids using annotate--*/ data anno; Function='OVAL'; DrawSpace='DATAVALUE'; HeightUnit='Data'; WidthUnit='Data'; Layer='Back'; X1=0; Y1=0; Linethickness=1; Linecolor='lightGray'; do Height=20 to 200 by 20; Width=height; output; end; run; ods graphics / reset attrpriority=color width=4in height=3in imagename='Wind_Polar'; title h=10pt 'Wind Rose created using SAS SGPLOT Procedure'; proc sgplot data=WindPolar aspect=1 noborder nowall noautolegend sganno=anno subpixel; format label dir.; format knots knots.; styleattrs datacolors=(forestgreen lightgreen gold cxD00000); polygon x=x y=y id=id / dataskin=sheen fill nooutline group=knots name='a'; vector x=x2 y=y2 / xorigin=x1 yorigin=y1 lineattrs=(color=lightGray) noarrowheads; text x=xl y=yl text=label / textattrs=(size=7); keylegend 'a' / position=right across=1; xaxis display=none; yaxis display=none; run;