*************************************************************; * 1) Press Ctrl+A to select the entire program, then press *; * Ctrl+C to copy it. *; * 2) In your SAS session, create a new program. Press *; * Ctrl+V to paste the code. *; * 3) Modify the path in the %LET statement to match the *; * location of your course data. *; * 4) Run the program to generate the files used in the *; * Visualizing Data with SAS Graphics Procedures lesson. *; *************************************************************; %let path=s:/workshop; ***********************************************; * Alternate Data Locations *; * DO NOT CHANGE THE FOLLOWING CODE UNLESS *; * DIRECTED TO DO SO BY YOUR INSTRUCTOR. *; ***********************************************; *%let path=s:/workshop/pg1m6; *%let path=c:/workshop/pg1m6; *%let path=c:/SAS_Education/pg1m6; *%let path=c:/SAS_Education/lwpg1m6; ***********************************************; * WARNING: DO NOT ALTER CODE BELOW THIS LINE *; * UNLESS DIRECTED TO DO SO BY YOUR INSTURCTOR.*; ***********************************************; data _null_; file "&path/activities/p109a02.sas"; put '*************************************************;'; put '* Visualizing Data with SAS Graphics Procedures *;'; put '* Activity 2 *;'; put '*************************************************;'; put; put 'ods graphics on;'; put '*ods select histogram;'; put 'proc univariate data=pg1.storm_final;'; put ' var MaxWindMPH;'; put 'run;'; run; data _null_; file "&path/activities/p109a04.sas"; put '*************************************************;'; put '* Visualizing Data with SAS Graphics Procedures *;'; put '* Activity 4 *;'; put '*************************************************;'; put; put 'title "Storms by Basin";'; put 'proc sgplot data=pg1.storm_final;'; put ' vbar BasinName;'; put 'run;'; put 'title;'; run; data _null_; file "&path/activities/p109a05.sas"; put '*************************************************;'; put '* Visualizing Data with SAS Graphics Procedures *;'; put '* Activity 5 *;'; put '*************************************************;'; put; put 'title "Storms by Basin";'; put 'proc sgplot data=pg1.storm_final;'; put ' hbar BasinName;'; put 'run;'; put 'title;'; run; data _null_; file "&path/activities/p109a06.sas"; put '*************************************************;'; put '* Visualizing Data with SAS Graphics Procedures *;'; put '* Activity 6 *;'; put '*************************************************;'; put; put 'title "Storms by Basin";'; put 'proc sgplot data=pg1.storm_final;'; put ' vbar BasinName / group=BasinName;'; put 'run;'; put 'title;'; run; data _null_; file "&path/activities/p109a08.sas"; put '*************************************************;'; put '* Visualizing Data with SAS Graphics Procedures *;'; put '* Activity 8 *;'; put '*************************************************;'; put; put 'title "Averge Miles per Gallon by Car Type";'; put 'proc sgplot data=sashelp.cars;'; put ' where Type ne "Hybrid";'; put ' vbar Type / response=MPG_Highway stat=mean barwidth=1;'; put ' *vbar Type / response=MPG_City stat=mean barwidth=.8;'; put 'run;'; put 'title;'; run; data _null_; file "&path/activities/p109a09.sas"; put '*************************************************;'; put '* Visualizing Data with SAS Graphics Procedures *;'; put '* Activity 9 *;'; put '*************************************************;'; put; put '*ods graphics / width=20cm height=8cm;'; put 'title "Number of Storms by Season";'; put 'proc sgplot data=pg1.storm_final;'; put ' vline Season;'; put 'run;'; put 'title;'; put '*ods graphics / reset;'; run; data _null_; file "&path/activities/p109a09a.sas"; put '*************************************************;'; put '* Visualizing Data with SAS Graphics Procedures *;'; put '* Activity 9 - Alternate Solution with Macro *;'; put '*************************************************;'; put; put '/*Calculate the mean storms per season and load into */'; put '/*a macro variable named AvgCount*/'; put 'proc sql noprint;'; put ' select mean(StormCount) format=4.1'; put ' into :AvgCount'; put ' from (select count(*) as StormCount'; put ' from pg1.storm_final'; put ' group by Season);'; put 'quit;'; put; put '/*Create the graph and use the AvgCount macro variable*/'; put '/*for the reference line and footnote.*/'; put 'ods graphics / width=20cm height=8cm;'; put 'title "Number of Storms by Season";'; put 'footnote "Average Number of Storms per Season: " color=red "&AvgCount";'; put 'proc sgplot data=pg1.storm_final;'; put ' vline Season;'; put ' refline &AvgCount / label="Avg Storms per Season" lineattrs=(color=red);'; put 'run;'; put 'title;footnote;'; put 'ods graphics / reset;'; run; data _null_; file "&path/activities/p109a10.sas"; put '*************************************************;'; put '* Visualizing Data with SAS Graphics Procedures *;'; put '* Activity 10 *;'; put '*************************************************;'; put; put 'ods graphics / width=20cm height=8cm;'; put 'title "Number of Storms by Season";'; put 'proc sgplot data=pg1.storm_final;'; put ' vline Season;'; put ' refline 81.4 / label="Avg Storms per Season";'; put 'run;'; put 'title;'; put 'ods graphics / reset;'; run; data _null_; file "&path/activities/p109a11.sas"; put '*************************************************;'; put '* Visualizing Data with SAS Graphics Procedures *;'; put '* Activity 11 *;'; put '*************************************************;'; put; put 'title "Average Maximum Wind Speed by Season";'; put 'proc sgplot data=pg1.storm_final;'; put ' vline Season / response=MaxWindMPH stat=mean;'; put ' where Season between 2000 and 2016;'; put 'run;'; put 'title;'; run; data _null_; file "&path/activities/p109a12.sas"; put '*************************************************;'; put '* Visualizing Data with SAS Graphics Procedures *;'; put '* Activity 12 *;'; put '* NOTE: The GROUP= option requires SAS 9.4M6 *;'; put '*************************************************;'; put; put 'title "Storms in 2016 Season";'; put 'proc sgmap plotdata=pg1.storm_final;'; put ' where Season=2016;'; put ' esrimap url="http://services.arcgisonline.com/arcgis/rest/services/World_Physical_Map";'; put ' scatter x=Lon y=Lat;'; put 'run;'; put 'title;'; run; data _null_; file "&path/activities/p109a13.sas"; put '*************************************************;'; put '* Visualizing Data with SAS Graphics Procedures *;'; put '* Activity 13 *;'; put '*************************************************;'; put; put '%let Year=2015;'; put '%let Basin=North Atlantic;'; put; put 'title1 "Tropical Storms in &Year Season";'; put 'title2 "&Basin Basin";'; put 'proc sgmap plotdata=pg1.storm_final;'; put ' where Season=2015 and BasinName="&Basin";'; put ' esrimap url="http://services.arcgisonline.com/arcgis/rest/services/World_Physical_Map";'; put ' bubble x=lon y=lat size=maxwindmph / datalabel=Name datalabelattrs=(color=red);'; put 'run;'; put 'title;'; run; data _null_; file "&path/activities/p109a14.sas"; put '*************************************************;'; put '* Visualizing Data with SAS Graphics Procedures *;'; put '* Activity 14 *;'; put '* NOTE: The NOAUTOLEGEND and GROUP= options *;'; put '* require SAS 9.4M6 *;'; put '*************************************************;'; put; put '%let year=2016;'; put '%let Basin=South Indian;'; put 'data map;'; put ' set pg1.storm_final;'; put ' length maplabel $ 20;'; put ' where season=&year and basinname="&basin";'; put ' if maxwindmph>100 then do;'; put ' maplabel=cats(name,"-",MaxWindMPH,"MPH");'; put ' Over100=1;'; put ' end;'; put ' else Over100=0;'; put ' keep lat lon maplabel maxwindmph Over100;'; put 'run;'; put; put 'title1 "Tropical Storms in &year Season";'; put 'title2 "&basin Basin";'; put 'footnote1 "Storms with MaxWind>100 MPH are labeled";'; put; put 'proc sgmap plotdata=map noautolegend;'; put ' esrimap url="http://services.arcgisonline.com/arcgis/rest/services/World_Physical_Map";'; put ' bubble x=lon y=lat size=maxwindmph / group='; put ' datalabel='; put ' datalabelattrs=(color=red size=9pt family="Arial");'; put 'run;'; put 'title;footnote;'; run; data _null_; file "&path/activities/p109a15.sas"; put 'ods html path="&outpath" file="GraphExamples.html" style=seaside;'; put '/*Histogram*/'; put 'title "Histogram with SGPLOT";'; put 'title2 "Distribution of Maximum Wind Speed";'; put 'proc sgplot data=pg1.storm_final;'; put ' density MaxWindMPH / type=normal lineattrs=(color=red) legendlabel="Maximum Wind";'; put ' histogram MaxWindMPH / transparency=0.75 fillattrs=(color=bigb);'; put 'run;'; put; put '/*Scatter Plot*/'; put 'title "Scatter Plot with SGPLOT";'; put 'title2 "Maximum Wind by Minimum Pressure";'; put 'title3 "Grouped by Ocean";'; put 'ods graphics on / attrpriority=none;'; put 'proc sgplot data=pg1.storm_final;'; put ' scatter x=MaxWindKM y=MinPressure / group=Ocean markerattrs=(size=8px) transparency=.2;'; put ' styleattrs datasymbols=(circlefilled squarefilled starfilled);'; put ' where Season=2016;'; put 'run;'; put; put '/*Series and Bubble Plot*/'; put '/*Need to pre-summarize data*/'; put 'proc means data=pg1.storm_final noprint;'; put ' var MaxWindMPH;'; put ' class Season;'; put ' output out=storm_stats mean=AvgWind n=Count;'; put ' ways 1;'; put ' where season between 2000 and 2016;'; put 'run;'; put; put 'title "Bubble and Series Plot with SGPLOT";'; put 'title2 "Average Wind by Season";'; put 'title3 "Bubble Size=Number of Storms";'; put 'proc sgplot data=storm_stats noautolegend;'; put ' bubble x=Season y=AvgWind size=Count / dataskin=gloss;'; put ' series x=Season y=AvgWind;'; put ' xaxis type=discrete;'; put 'run;'; put; put '/*Box Plot */'; put 'title "Box Plot with SGPLOT";'; put 'title2 "Distribution of Maximum Wind Speed by Ocean and Basin";'; put 'proc sgplot data=pg1.storm_final;'; put ' vbox MaxWindMPH / category=Ocean group=BasinName boxwidth=.8;'; put 'run;'; put; put '/*Bar Chart*/'; put 'title "Bar Chart with SGPLOT";'; put 'title2 "Distribution of Storms by Basin";'; put 'proc sgplot data=pg1.storm_final noautolegend;'; put ' vbar BasinName / group=BasinName categoryorder=respdesc seglabel seglabelattrs=(family=Arial size=12pt);'; put ' xaxis label=" ";'; put ' yaxis label="Number of Storms";'; put 'run;'; put; put '/*Donut Chart*/'; put '/*PROC SGPIE is pre-production in SAS 9.4M6. */'; put 'title "Donut Chart with SGPIE (preproduction in SAS 9.4M6)";'; put 'proc sgpie data=pg1.storm_final;'; put ' where Season=2016;'; put ' donut BasinName / holevalue holelabel="2016 Storms"'; put ' ringsize=.2'; put ' datalabelattrs=(size=10pt)'; put ' datalabelloc=outside'; put ' dataskin=pressed;'; put 'run;'; put; put '/*Line Plot with Panels*/'; put 'proc freq data=pg1.storm_final noprint;'; put ' where Season<=2016;'; put ' tables Season / out=StormCount;'; put 'run;'; put; put 'data stormcount;'; put ' set stormcount;'; put ' Decade=floor(Season/10)*10;'; put ' DYear=mod(season,10)+1;'; put ' keep Season Decade DYear Count;'; put 'run;'; put; put 'ods graphics / width=1000px height=250px;'; put 'title "Band and Line Plot with SGPANEL";'; put 'title2 "Frequency of Storms by Year";'; put 'proc sgpanel data=StormCount noautolegend;'; put ' panelby Decade / layout=panel columns=4 rows=1 noheader novarname noborder;'; put ' band x=DYear lower=0 upper=count / group=decade transparency=.50;'; put ' series x=DYear y=count / group=decade lineattrs=(thickness=3);'; put ' inset Decade / position=bottom nolabel textattrs=(color=gray33 size=14pt);'; put ' colaxis'; put ' values=(1 to 12 by 12)'; put ' valueattrs=(color=gray33 size=10pt)'; put ' display=(nolabel noline noticks novalues)'; put ' grid offsetmin=0 offsetmax=0;'; put ' rowaxis values=(0 to 100 by 20) display=(nolabel noline noticks)'; put ' valueattrs=(color=gray33 size=10pt)'; put ' grid offsetmin=0 offsetmax=0;'; put 'run;'; put 'title;footnote;'; put 'ods html close;'; put 'ods graphics / reset;'; run;