/* Read the data directly from the Internet */ /*filename webfile url "http://academic.udayton.edu/kissock/http/Weather/gsod95-current/NYALBANY.txt" */ /* proxy='http://inetgw.fyi.sas.com:80' debug;*/ filename webfile url "http://academic.udayton.edu/kissock/http/Weather/gsod95-current/NYALBANY.txt" debug; data tempdata; infile webfile; input month day year temperature; format date date9.; date=MDY(month, day, year); dayofyear=0; dayofyear=put(date,julday3.); if temperature^=-99 then output; run; data _null_; set tempdata end=last; retain min max; min=min(min, temperature); max=max(max, temperature); if last then do; output; call symputx ('MIN', min); call symputx ('MAX', max); call symputx ('RANGE', max-min); end; run; proc format; value deg 0='Jan 1' 30='Feb 1' 60='Mar 1' 90='Apr 1' 120='May 1' 150='Jun 1' 180='Jul 1' 210='Aug 1' 240='Sep 1' 270='Oct 1' 300='Nov 1' 330='Dec 1' 360='Dec 1'; run; /*--remap the x axis to 0-360--*/ data linear; set tempdata end=last; day=360*dayofyear/366; if date < '01Dec2011'd then temp1=temperature; else temp2=temperature; run; /*--Create linear plot using SGPLOT procedure, also get output data--*/ ods listing gpath='C:\'; ods graphics / reset width=5in height=3in imagename='Linear_SG' antialiasmax=6300; title 'Temperature in Albany, NY (1995 - 2012)'; proc sgplot data=linear; format day deg.; scatter x=day y=temp1 / markerattrs=(symbol=circlefilled size=3 color=red) legendlabel='Historical' transparency=0.8; scatter x=day y=temp2 / markerattrs=(symbol=starfilled size=5 color=black) legendlabel='2012'; xaxis values=(0 to 330 by 30) valueshint; yaxis grid label='Temperature (F)'; run; title; /*--Create linear plot using SGPLOT procedure, also get output data--*/ ods graphics / reset width=5in height=3in imagename='Linear_SG_Fit' antialiasmax=6300; title 'Temperature in Albany, NY (1995 - 2012)'; ods output sgplot=sgplot; proc sgplot data=linear; format day deg.; scatter x=day y=temp1 / markerattrs=(symbol=circlefilled size=3 color=red) legendlabel='Historical' transparency=0.8; scatter x=day y=temp2 / markerattrs=(symbol=starfilled size=5 color=black) legendlabel='2012'; reg x=day y=temp1 / degree=5 nomarkers lineattrs=graphfit; xaxis values=(0 to 330 by 30) valueshint; yaxis grid label='Temperature (F)'; run; title; data sgplot2; set sgplot (rename=(regression_day_temp1_degree_5__x=reg_day regression_day_temp1_degree_5__y=predict)); run; /*--Transform temp and fit values in to polar coordinates--*/ data polar; set sgplot2 end=last; keep x1 y1 x2 y2 xp yp xo yo xr yr xl yl xel yel deg semi origin slope; theta=2*3.14159265*day/360; reg_theta=2*3.14159265*reg_day/360; semi=0.01; origin=0; slope=0; /*--Compute equivalent cartesean coordinates for polar plot of temp--*/ x1=(temp1-&MIN) * cos(theta); y1=(temp1-&MIN) * sin(theta); x2=(temp2-&MIN) * cos(theta); y2=(temp2-&MIN) * sin(theta); /*--Compute equivalent cartesean coordinates for polar plot of predict--*/ xp=(predict-&MIN) * cos(reg_theta); yp=(predict-&MIN) * sin(reg_theta); /*--Compute cartesean coordinates for polar plot for radial gridlines--*/ if last then do; do deg=0 to 330 by 30; th=2*3.14159265*deg/360; xo=0; yo=0; xr= (100) * cos(th); yr= (100) * sin(th); xl= (105) * cos(th); yl= (105) * sin(th); output; end; /*--Compute cartesean coordinates for polar plot for circular gridlines--*/ do semi=20 to 100 by 20; origin=0; slope=0; xel=.; if semi < 100 then do; xel=0; yel=semi+5; end; output; end; end; else output; run; /*proc print data=polar;run;*/ proc template; define statgraph polar; dynamic _fit; begingraph / designwidth=9in designheight=9in; entrytitle 'Temperature in Albany, NY (1995 - 2012)'; layout overlay / xaxisopts=(display=none) yaxisopts=(display=none); scatterplot x=x1 y=y1 / markerattrs=(symbol=circlefilled size=3 color=red) name='a' legendlabel='Historical' datatransparency=0.8; scatterplot x=x2 y=y2 / markerattrs=(symbol=starfilled size=5 color=black) name='b' legendlabel='2012'; if (exists(_fit)) seriesplot x=xp y=yp/ lineattrs=graphfit; endif; vectorplot x=xr y=yr xorigin=xo yorigin=yo / arrowheads=false lineattrs=graphgridlines; scatterplot x=xl y=yl / markercharacter=deg markercharacterattrs=(size=10); scatterplot x=xel y=yel / markercharacter=semi markercharacterattrs=(size=10); ellipseparm semimajor=semi semiminor=semi xorigin=origin yorigin=origin slope=slope / outlineattrs=graphgridlines; discretelegend 'a' 'b'; endlayout; endgraph; end; run; /*--Polar plot--*/ ods graphics / reset width=5in height=5in noborder antialiasmax=6300 imagename='polar_GTL'; proc sgrender data=polar template=polar; format deg deg.; run; /*--Polar plot with fit--*/ ods graphics / reset width=5in height=5in noborder antialiasmax=6300 imagename='polar_GTL_Fit'; proc sgrender data=polar template=polar; format deg deg.; dynamic _fit='Yes'; run;