* TAB 1. SCATTER; * SCATTER CHARTS: EXERCISE 1; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgplot data=sashelp.class; title "Weight*Height"; scatter x=weight y=height; run; * SCATTER CHARTS: EXERCISE 2; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgplot data=sashelp.class; title "Weight*Height"; scatter x=weight y=height / markerattrs=(size=12pt symbol=circlefilled) jitter; run; * SCATTER CHARTS: EXERCISE 3; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgplot data=sashelp.class; title "Weight*Height"; styleattrs datacontrastcolors=(blue pink); scatter x=weight y=height / markerattrs=(size=12pt symbol=circlefilled) jitter group=sex; run; * SCATTER CHARTS: EXERCISE 4; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgplot data=sashelp.class; title "Weight*Height"; styleattrs datacontrastcolors=(blue vipk); * VIPK=Vivid Pink; symbolchar name=Smiley char='263A'x; * Unicode smiley face; scatter x=weight y=height / markerattrs=(size=36pt symbol=Smiley) jitter group=sex; run; * SCATTER CHARTS: EXERCISE 5; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgplot data=sashelp.class; title "Weight*Height"; scatter x=weight y=height / markerattrs=(size=12pt symbol=circlefilled) jitter colorresponse=age colormodel=(lightgreen darkgreen) datalabel=name datalabelattrs=(color=black); xaxis label="Weight (lbs)"; yaxis label="Height (in)"; run; * TAB 2. LINE; * LINE CHARTS: EXERCISE 1; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgplot data=sashelp.prdsale; title "Sales"; vline month / response=actual; run; * LINE CHARTS: EXERCISE 2; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgplot data=sashelp.prdsale; title "Sales"; hline month / response=actual; run; * LINE CHARTS: EXERCISE 3; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgplot data=sashelp.prdsale; title "Sales"; vline month / response=actual markers; xaxis display=(nolabel) valuesformat=monyy5. type=time; run; * LINE CHARTS: EXERCISE 4; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgplot data=sashelp.prdsale; title "Actual Sales by Product Type"; vline month / response=actual markers markerattrs=(symbol=circlefilled) group=prodtype; xaxis display=(nolabel) type=time; yaxis display=(nolabel); format month yymmdd10.; run; * LINE CHARTS: EXERCISE 5; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgplot data=sashelp.prdsale; title "Actual vs Predicted Sales by Product Type"; vline month / response=actual markers markerattrs=(symbol=circlefilled) group=prodtype name="actual"; vline month / response=predict markers markerattrs=(symbol=circle) group=prodtype lineattrs=(pattern=dot) name="predict"; xaxis display=(nolabel) type=time; yaxis display=(nolabel); format month yymmdd10.; keylegend "actual" / title="ACT" position=bottom noborder; keylegend "predict" / title="PRD" position=bottom noborder; run; * TAB 3. STEP; * STEP CHARTS: EXERCISE 1; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sql noprint; create table orsalesum as select quarter, sum(profit) as profit from sashelp.orsales group by 1 order by 1; proc sgplot data=orsalesum; title "Quarterly Profit"; step x=quarter y=profit; run; * STEP CHARTS: EXERCISE 2; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sql noprint; create table orsalesum as select quarter, sum(profit) as profit from sashelp.orsales group by 1 order by 1; proc sgplot data=orsalesum; title "Quarterly Profit"; step x=quarter y=profit / markers markerattrs=(symbol=circlefilled) datalabel=profit justify=center; format profit dollar10.; xaxis display=(nolabel) grid; yaxis display=(nolabel) grid; run; * STEP CHARTS: EXERCISE 3; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sql noprint; create table orsalesum2 as select quarter, product_line, sum(profit) as profit from sashelp.orsales where product_line in ('Children', 'Sports') group by 1, 2 order by 1, 2; proc sgplot data=orsalesum2; title "Quarterly Profit"; step x=quarter y=profit / markers markerattrs=(symbol=circlefilled) justify=center datalabel group=product_line curvelabel curvelabelloc=outside; format profit dollar10.; xaxis display=(nolabel) grid; yaxis display=(nolabel) grid; run; * TAB 4. BAR; * BAR CHARTS: EXERCISE 1; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgplot data=sashelp.prdsale(where=(year(month)=1994)); title "Sales"; vbar month / response=actual; run; * BAR CHARTS: EXERCISE 2; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgplot data=sashelp.prdsale(where=(year(month)=1994)); title "Sales"; hbar month / response=actual; run; * BAR CHARTS: EXERCISE 3; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgplot data=sashelp.prdsale(where=(year(month)=1994)); title "Sales"; vbar month / response=actual group=division; format month monyy5.; run; * BAR CHARTS: EXERCISE 4; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgplot data=sashelp.prdsale(where=(year(month)=1994)); title "Sales"; vbar month / response=actual group=division groupdisplay=cluster; format month monyy5.; run; * BAR CHARTS: EXERCISE 5; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgplot data=sashelp.prdsale(where=(year(month)=1994)); styleattrs datacolors=(palegreen lightblue); title height=12pt "1994 MONTHLY SALES"; vbar month / response=actual group=division datalabel datalabelattrs=(size=8.5pt) seglabel seglabelformat=dollar9. seglabelattrs=(size=8.5pt); xaxis display=(nolabel); yaxis display=(nolabel) grid; keylegend / title="" noborder; format actual dollar9. month monname3.; run; * TAB 5. COMBO; * COMBO CHARTS: EXERCISE 1; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgplot data=sashelp.class; title "Height vs. Weight"; vbar name / response=height; vline name / response=weight y2axis; run; * COMBO CHARTS: EXERCISE 2; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgplot data=sashelp.class noautolegend; title "Height (in) vs. Weight (lbs)"; vbar name / response=height fillattrs=(color=blue transparency=.80) nooutline datalabel datalabelattrs=(weight=bold) categoryorder=respasc; vline name / response=weight y2axis markers markerattrs=(symbol=circlefilled) datalabel datalabelattrs=(weight=bold); xaxis display=(nolabel) valuesrotate=vertical; yaxis display=(nolabel); y2axis display=(nolabel) values=(0 to 180 by 20); format weight 3.; run; * COMBO CHARTS: EXERCISE 3; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgplot data=sashelp.class; title "Height vs. Weight Scatter + REG"; styleattrs datacontrastcolors=(blue pink); reg x=weight y=height; scatter x=weight y=height / markerattrs=(size=10pt symbol=circlefilled) jitter group=sex; run; * COMBO CHARTS: EXERCISE 4; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgplot data=sashelp.class; title "Height vs. Weight Scatter + LOESS"; styleattrs datacontrastcolors=(blue pink); loess x=weight y=height; scatter x=weight y=height / markerattrs=(size=10pt symbol=circlefilled) jitter group=sex; run; * TAB 6. TABLE; * TABLE CHARTS: EXERCISE 1; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgplot data=sashelp.prdsale(where=(year=1993)); title "1993 Actual vs Predicted Sales"; vline month / markers response=actual; vline month / markers response=predict; format month monyy5. actual predict dollar7.0; xaxistable actual predict / location=outside; keylegend / location=inside position=topright; xaxis display=(nolabel); run; * TAB 7. DOT; * DOT CHARTS: EXERCISE 1; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgplot data=sashelp.class; title "Class by Age"; dot age; run; * DOT CHARTS: EXERCISE 2; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgplot data=sashelp.class; title "Class Mean Age"; dot age / response=height stat=mean group=sex datalabel=sex datalabelattrs=(size=10pt); run; * DOT CHARTS: EXERCISE 3; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc format; picture inchF low-high ='99"'; proc sgplot data=sashelp.class; title "Mean Height by Age"; dot age / response=height stat=mean limitstat=stddev numstd=1 markerattrs=(size=12pt symbol=circlefilled); xaxis valuesformat=inchF.; yaxis reverse; run; * TAB 8. BUBBLE; * BUBBLE CHARTS: EXERCISE 1; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgplot data=sashelp.class; title "Students by Height-Weight-Age"; bubble x=height y=weight size=age; run; * BUBBLE CHARTS: EXERCISE 2; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgplot data=sashelp.class; title "Students by Height-Weight-Age, Grouped by Gender"; bubble x=height y=weight size=age / group=sex; run; * BUBBLE CHARTS: EXERCISE 3; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgplot data=sashelp.class; title "Students by Height-Weight-Age, Grouped by Gender"; bubble x=height y=weight size=age / group=sex transparency=.5 dataskin=sheen datalabel=name datalabelattrs=(color=black); run; * BUBBLE CHARTS: EXERCISE 4; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sql noprint; create table orsalesum as select quarter, product_category, sum(profit) as profit format=dollar10. from sashelp.orsales group by 1, 2 order by 1, 2; proc sgplot data=orsalesum; title "Orion Quarterly Sales by Product Category"; bubble y=product_category x=quarter size=profit / bradiusmax=12pt dataskin=sheen fillattrs=(color=blue); xaxis display=(nolabel) valuesrotate=vertical; yaxis display=(nolabel); run; * TAB 9. BOX; * BOX CHARTS: EXERCISE 1; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgplot data=sashelp.cars; title "City MPG"; hbox mpg_city; run; * BOX CHARTS: EXERCISE 2; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgplot data=sashelp.cars; title "City MPG"; vbox mpg_city; run; * BOX CHARTS: EXERCISE 3; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgplot data=sashelp.cars; title "City MPG"; vbox mpg_city / datalabel=model; run; * BOX CHARTS: EXERCISE 4; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgplot data=sashelp.cars noautolegend; title "MPG City vs Number of Cylinders"; hbox mpg_city / group=cylinders category=cylinders; yaxis reverse; xaxis grid values=(0 to 65 by 5); run; * BOX CHARTS: EXERCISE 5; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgplot data=sashelp.cars; title "MPG City vs Number of Cylinders"; vbox mpg_city / category=cylinders connect=median datalabel=model dataskin=gloss; yaxis grid values=(0 to 65 by 5); format model $13.; run; * TAB 10. HIGHLOW; * HIGHLOW CHARTS: EXERCISE 1; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgplot data=sashelp.stocks; title "Intel (1999-2000)"; where stock='Intel' and '01jan1999'd<=date<'01jan2001'd; highlow x=date high=high low=low; run; * HIGHLOW CHARTS: EXERCISE 2; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgplot data=sashelp.stocks; title "Intel Monthly Open-Close-High-Low Stock Prices"; where stock='Intel' and '01jan1999'd<=date<'01jan2001'd; highlow x=date high=high low=low / open=open close=close; xaxis display=(nolabel); yaxis display=(nolabel) grid; run; * HIGHLOW CHARTS: EXERCISE 3; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgplot data=sashelp.stocks; title "Intel Monthly High-Low Stock Prices"; where stock='Intel' and '01jan1999'd<=date<'01jan2001'd; highlow y=date high=high low=low / type=bar nooutline barwidth=.75 fill fillattrs=(color="verylightblue") lowlabel=low highlabel=high open=open close=close; xaxis display=(nolabel) grid valueattrs=(size=8pt); yaxis display=(nolabel) interval=month reverse valuesformat=monyy5. valueattrs=(size=8pt); run; * TAB 11. WATERFALL; * WATERFALL CHARTS: EXERCISE 1; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgplot data=sashelp.failure; title "Counts of Failure by Cause"; waterfall category=cause response=count; run; * WATERFALL CHARTS: EXERCISE 2; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgplot data=sashelp.failure; title "Counts of Failure by Cause"; waterfall category=cause response=count / datalabel fillattrs=(color=lightred) finalbarattrs=(color=red); xaxis display=(nolabel); yaxis display=(nolabel); run; * WATERFALL CHARTS: EXERCISE 3; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sql noprint; create table heartdeaths as select deathcause, sum(-1) as Deaths from sashelp.heart where status='Dead' group by 1; select count(*) into :Participants from sashelp.heart; proc sgplot data=heartdeaths; title "Heart Study: Waterfall Chart of Death Causes"; waterfall category=deathcause response=deaths / datalabel fillattrs=(color=black) initialbarvalue=&Participants initialbarattrs=(color=green) finalbarattrs=(color=green); xaxis display=(nolabel); yaxis display=(nolabel); format deaths comma7.; run; * TAB 12. SERIES; * SERIES CHARTS: EXERCISE 1; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgplot data=sashelp.stocks; title "IBM (2000-2002)"; where stock="IBM" and '01jan2000'd<=date<'01jan2003'd; series x=date y=close; run; * SERIES CHARTS: EXERCISE 2; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgplot data=sashelp.stocks; title "Closing Stock Prices"; where '01jan2000'd<=date<'01jan2001'd; series x=date y=close / group=stock thickresp=volume curvelabel curvelabelloc=outside; footnote "Note: Line thickness varies based on trading volume"; run; footnote; run; * SERIES CHARTS: EXERCISE 3; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgplot data=sashelp.stocks noborder; title "IBM and MSFT Closing Stock Prices (2000-2002)"; where stock in ("IBM" "Microsoft") and '01jan2000'd<=date<'01jan2003'd; series x=date y=close / group=stock curvelabel curvelabelloc=outside; xaxis display=(nolabel) grid; yaxis display=(nolabel) grid; run; * SERIES CHARTS: EXERCISE 4; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgplot data=sashelp.stocks; where stock="IBM" and '01jan2000'd<=date<'01jan2003'd; title height=10pt "IBM Opening and Closing Stock Prices (2000-2002)"; series x=date y=open; series x=date y=close; run; * SERIES CHARTS: EXERCISE 5; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgplot data=sashelp.stocks; where stock="IBM" and '01jan2000'd<=date<'01jan2003'd; title height=10pt "IBM Opening and Closing Stock Prices (2000-2002)"; series x=date y=open / lineattrs=(pattern=dot thickness=3pt) smoothconnect; series x=date y=close / lineattrs=(pattern=solid thickness=3pt) smoothconnect; xaxis display=(nolabel); yaxis display=(nolabel); run; * TAB 13. HISTOGRAM; * HISTOGRAM CHARTS: EXERCISE 1; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgplot data=sashelp.baseball; title "Home Runs (1986 Season)"; histogram nhome; run; * HISTOGRAM CHARTS: EXERCISE 2; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgplot data=sashelp.baseball; title "1986 Major League Baseball Home Run Distribution"; histogram nhome / datalabel=count nbins=10 showbins dataskin=pressed filltype=gradient fillattrs=(color=dodgerblue); run; * HISTOGRAM CHARTS: EXERCISE 3; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc format; picture pctF low-high ='099%'; proc sgplot data=sashelp.baseball noautolegend; title "1986 Major League Baseball Home Run Distribution"; histogram nhome / datalabel=count nbins=10 showbins dataskin=pressed filltype=gradient fillattrs=(color=dodgerblue); density nhome / type=kernel; fringe nhome; yaxis display=(nolabel) valuesformat=pctf. grid; run; * TAB 14. VECTOR; * VECTOR CHARTS: EXERCISE 1; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgplot data=sashelp.class; title "Weight*Height Vector Plot"; vector x=weight y=height; run; * VECTOR CHARTS: EXERCISE 2; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sql noprint; select avg(weight) format=5.1, avg(height) format=5.1 into :avgweight, :avgheight from sashelp.class; proc sgplot data=sashelp.class; title "Weight*Height Vector Plot"; vector x=weight y=height / xorigin=&avgweight yorigin=&avgheight; run; * VECTOR CHARTS: EXERCISE 3; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgplot data=sashelp.class; title "Weight*Height Vector Plot"; vector x=weight y=height / xorigin=&avgweight yorigin=&avgheight; refline &avgweight / axis=x labelloc=inside label labelattrs=(size=7pt) lineattrs=(pattern=dash); refline &avgheight / axis=y labelloc=inside label labelattrs=(size=7pt) lineattrs=(pattern=dash); run; * VECTOR CHARTS: EXERCISE 4; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc format; picture inchF low-high ='99"'; picture lbsF low-high ='009 lbs'; proc sgplot data=sashelp.class; title "'Distance' of Students from Mean Class Weight/Height"; vector x=weight y=height / xorigin=&avgweight yorigin=&avgheight datalabel=name; refline &avgweight / axis=x labelloc=inside label labelattrs=(size=7pt) lineattrs=(pattern=dash); refline &avgheight / axis=y labelloc=inside label labelattrs=(size=7pt) lineattrs=(pattern=dash); xaxis display=(nolabel); yaxis display=(nolabel); format weight lbsF. height inchF.; run; * TAB 15. TEXT; * TEXT CHARTS: EXERCISE 1; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgplot data=sashelp.class; title "Weight*Height Text Plot"; text x=weight y=height text=name; run; * TEXT CHARTS: EXERCISE 2; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sql noprint; create table classminmax as select c.*, case when height=minheight or height=maxheight then name end as showname from sashelp.class c, (select min(height) as minheight, max(height) as maxheight from sashelp.class) as minmax; proc sgplot data=classminmax nowall noautolegend; title "Class Weight by Height, With Names of Tallest & Shortest"; scatter x=weight y=height / transparency=.7 markerattrs=(symbol=circlefilled size=8pt color=blue); text x=weight y=height text=showname / textattrs=(size=10pt color=black weight=bold) position=top strip; xaxis display=(nolabel); yaxis display=(nolabel); run; * TAB 16. NEEDLE; * NEEDLE CHARTS: EXERCISE 1; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgplot data=sashelp.class; title "Height - Needle Plot"; needle x=name y=height; run; * NEEDLE CHARTS: EXERCISE 2; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc format; picture inchF low-high ='99.9"'; proc sgplot data=sashelp.class; title "Class Height 'Lollipop' Chart"; needle x=name y=height / datalabel datalabelpos=center datalabelattrs=(color=white size=10pt weight=bold) markers markerattrs=(symbol=circlefilled size=32pt); xaxis display=(nolabel); yaxis display=none; format height inchF.; run; * NEEDLE CHARTS: EXERCISE 3; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc format; picture inchF low-high ='99.9"'; proc sql noprint; select avg(height) into :avgheight from sashelp.class; proc sgplot data=sashelp.class; title "Class Heights vs. Avg Class Height"; needle x=name y=height / datalabel datalabelpos=right datalabelattrs=(color=black size=10pt weight=bold) lineattrs=(thickness=2pt color=dodgerblue) markers markerattrs=(symbol=circlefilled color=dodgerblue size=10pt) baseline=&avgHeight baselineattrs=(color=dodgerblue thickness=2pt); xaxis display=(nolabel); yaxis display=none; format height inchF.; run; * TAB 17. HEATMAP; * HEATMAP CHARTS: EXERCISE 1; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgplot data=sashelp.heart; title "Framingham Heart Study"; heatmap x=weight y=cholesterol; run; * HEATMAP CHARTS: EXERCISE 2; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgplot data=sashelp.heart; title "Framingham Heart Study (Death Cause Coronary Heart Disease)"; where deathcause="Coronary Heart Disease"; heatmap x=weight y=cholesterol; run; * HEATMAP CHARTS: EXERCISE 3; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgplot data=sashelp.heart; title "Framingham Heart Study"; heatmap x=weight y=cholesterol / colormodel=(green yellow red) nxbins=50 nybins=50 showxbins showybins; run; * HEATMAP CHARTS: EXERCISE 4; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgplot data=sashelp.heart; title "Framingham Heart Study"; heatmap x=bp_status y=weight_status / colormodel=(green yellow red); run; * TAB 18. BAND; * BAND CHARTS: EXERCISE 1; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgplot data=sashelp.classfit; title "Weight Limits on the Y Axis (SASHELP.CLASSFIT)"; band x=name lower=lowermean upper=uppermean; run; * BAND CHARTS: EXERCISE 2; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgplot data=sashelp.classfit noautolegend; title "Weight Limits on the Y Axis (SASHELP.CLASSFIT)"; band x=name lower=lowermean upper=uppermean; needle x=name y=weight / markers markerattrs=(symbol=circlefilled); xaxis display=(nolabel); yaxis grid; run; * BAND CHARTS: EXERCISE 3; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sql noprint; create table orsalesum as select quarter, sum(profit) as profit from sashelp.orsales group by 1 order by 1; proc sgplot data=orsalesum; title "Quarterly Profit"; band x=quarter upper=profit lower=0 / fill fillattrs=(color=green transparency=.7); format profit dollar10.; xaxis display=(nolabel) grid; yaxis display=(nolabel) grid; run; * TAB 19. BLOCK; * BLOCK CHARTS: EXERCISE 1; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgplot data=sashelp.class; title "Class, Blocked by Age"; block x=name block=age; run; * BLOCK CHARTS: EXERCISE 2; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sort data=sashelp.class out=classSort; by height; proc sgplot data=classSort; styleattrs datacolors=(cxe5f5e0 cxc7e9c0 cxa1d99b cx74c476 cx41ab5d cx238b45); title "Class by Height, Blocked by Age"; block x=name block=age; series x=name y=height / markers markerattrs=(symbol=circlefilled); xaxis display=(nolabel); yaxis display=(nolabel) max=75; run; * BLOCK CHARTS: EXERCISE 3; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sql; create table prdsalemth as select month, put(month,monyy5.) as monyy, "Q"||put(quarter,1.) as qtr, sum(actual) as actual from sashelp.prdsale group by 1, 2, 3 order by 1, 2, 3; proc sgplot data=prdsalemth; styleattrs datacolors=(lightorange lightblue lightgreen lightyellow); title "Sales"; block x=monyy block=qtr / valuehalign=left; vbarparm category=monyy response=actual / fillattrs=(color=black) fill barwidth=.6 datalabel; xaxis display=(nolabel) discreteorder=data; yaxis display=(nolabel) offsetmax=0.1; run; * TAB 20. ATTRIBUTE MAPS; * ATTRIBUTE MAPS CHARTS: EXERCISE 1; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; data mapGender; input (ID value linecolor fillcolor)($); datalines; Gender F pink pink Gender M blue blue ; proc sgplot data=sashelp.class dattrmap=mapGender; title "Discrete Attribute Map Example (Color List)"; vbar age / group=sex groupdisplay=cluster attrid=Gender datalabel; run; * ATTRIBUTE MAPS CHARTS: EXERCISE 2; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; data mapWeight; input (ID min max color altcolor)($); datalines; weight _min_ 80 red red weight 80 100 blue blue weight 100 _max_ green green ; proc sgplot data=sashelp.class rattrmap=mapWeight; title "Range Attribute Map Example (Color List)"; scatter x=height y=weight / transparency=.5 colorresponse=weight rattrid=weight markerattrs=(symbol=circlefilled size=24pt); run; * ATTRIBUTE MAPS CHARTS: EXERCISE 3; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; data mapWeight2; input (ID min max)($) altcolormodel1:$10. altcolormodel2:$10.; datalines; weight _min_ _max_ lightgreen darkgreen ; proc sgplot data=sashelp.class rattrmap=mapWeight2; title "Range Attribute Map Example (Color Model)"; scatter x=height y=weight / colorresponse=weight rattrid=weight markerattrs=(symbol=circlefilled size=24pt); run; * TAB 21. ANNOTATE; * ANNOTATE CHARTS: EXERCISE 1; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; data anno; retain function "text" label "DRAFT" textcolor "gray" justify "center" textsize 180 transparency .3 width 200; proc sgplot data=sashelp.class sganno=anno; title "Annotation Example - Watermark"; vbar age / group=sex groupdisplay=cluster; run; * TAB 22. SGPANEL; * SGPANEL CHARTS: EXERCISE 1; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgpanel data=sashelp.class; title "Class Ages by Gender"; panelby sex; vbar age / colorresponse=weight colormodel=(lightblue blue) response=weight stat=mean colorstat=mean; run; * SGPANEL CHARTS: EXERCISE 2; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgpanel data=sashelp.cars; title "Cars - MSRP by Origin"; panelby origin; dot type / response=msrp stat=mean datalabel markerattrs=(size=16pt symbol=circlefilled color=blue); run; * SGPANEL CHARTS: EXERCISE 3; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgpanel data=sashelp.cars; title "Cars - MSRP by Origin"; panelby type; dot origin / response=msrp stat=mean datalabel markerattrs=(size=16pt symbol=circlefilled color=blue); run; * SGPANEL CHARTS: EXERCISE 4; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgpanel data=sashelp.cars noautolegend; title "Cars - MPG by Origin/Type"; panelby origin type / layout=lattice novarname uniscale=column onepanel; reg y=mpg_city x=weight / markerattrs=(color=blue); format weight comma8.; run; * SGPANEL CHARTS: EXERCISE 5; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgpanel data= sashelp.stocks; title "Stock Closing Prices by Quarter (1998-2003)"; panelby stock / rows=3 novarname uniscale=column noheader; title; inset stock / nolabel textattrs=(size=18pt); series x=date y=close / lineattrs=(thickness=3pt) lineattrs=(color=blue); colaxis values=('01jan1998'd to '01jan2004'd by quarter) min='01jan1998'd max='01jan2004'd display=(nolabel) grid valuesformat=yyq4.; rowaxis display=(nolabel) grid; run; * TAB 23. SGSCATTER; * SGSCATTER CHARTS: EXERCISE 1; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgscatter data=sashelp.cars; title "SGSCATTER Matrix of Car Characteristics"; matrix enginesize cylinders horsepower mpg_city; run; * SGSCATTER CHARTS: EXERCISE 2; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgscatter data=sashelp.cars; title "SGSCATTER Matrix of Car Characteristics"; matrix enginesize cylinders horsepower mpg_city / diagonal=(histogram) transparency=.2; run; * SGSCATTER CHARTS: EXERCISE 3; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgscatter data=sashelp.cars; title "SGSCATTER Plots of Car Characteristics"; plot mpg_city*(enginesize cylinders horsepower mpg_highway); run; * SGSCATTER CHARTS: EXERCISE 4; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgscatter data=sashelp.cars; title "SGSCATTER Plots of Car Characteristics"; plot mpg_city* (enginesize cylinders horsepower mpg_highway) / rows=3; run; * SGSCATTER CHARTS: EXERCISE 5; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgscatter data=sashelp.cars; title "SGSCATTER Plots of Car Characteristics"; plot mpg_city* (enginesize cylinders horsepower mpg_highway) / columns=4 reg; run; * SGSCATTER CHARTS: EXERCISE 6; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgscatter data=sashelp.cars; title "SGSCATTER Comparison Plots of Car Characteristics"; compare x=(enginesize cylinders horsepower mpg_highway) y=(mpg_city) / reg; run; * SGSCATTER CHARTS: EXERCISE 7; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sgscatter data=sashelp.cars; title "SGSCATTER Comparison Plots of Car Characteristics"; compare x=(enginesize cylinders horsepower) y=(mpg_city mpg_highway) / reg; run; * TAB 24. GTL; * GTL CHARTS: EXERCISE 1; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc template; define statgraph gtlStock; begingraph; layout lattice; seriesplot x=date y=close; needleplot x=date y=volume; endlayout; endgraph; end; proc sgrender data=sashelp.stocks template=gtlStock; title height=10pt "IBM Closing Stock Prices and Volume (1998-2005)"; where stock="IBM" and '01jan1998'd<=date<'01jan2005'd; run; * GTL CHARTS: EXERCISE 2; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc format; picture million low-high='0000' (mult=.00001); proc template; define statgraph gtlStock; begingraph; entrytitle "IBM (1998-2005)"; layout lattice / columndatarange=union rowweights=(.7 .3); seriesplot x=date y=close; needleplot x=date y=volume; columnaxes; columnaxis / griddisplay=on display=(line ticks tickvalues); endcolumnaxes; endlayout; endgraph; end; proc sgrender data=sashelp.stocks template=gtlStock; where stock="IBM" and '01jan1998'd<=date<'01jan2005'd; format volume million.; run; * TAB 25. PIE (GTL); * PIE CHARTS: EXERCISE 1; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc template; define statgraph pie; begingraph; entrytitle "Car Models by Number of Cylinders"; layout region; piechart category=cylinders; endlayout; endgraph; end; proc sgrender data=sashelp.cars template=pie; run; * PIE CHARTS: EXERCISE 2; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc template; define statgraph pie; begingraph; entrytitle "Car Models by Type"; layout region; piechart category=type / dataskin=gloss datalabellocation=outside; endlayout; endgraph; end; proc sgrender data=sashelp.cars template=pie; run; * TAB 26. MOSAIC (GTL); * MOSAIC CHARTS: EXERCISE 1; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc summary data=sashelp.cars nway; class origin type; var mpg_highway; output out=mileage mean=avgMpg N=count / noinherit; proc template; define statgraph mosaicPlotParm; begingraph; layout region; mosaicPlotParm category=(type origin) count=count / colorgroup=origin; endlayout; endgraph; end; proc sgrender data=mileage template=mosaicPlotParm; title "Mosaic Plot of Car Origin/Type/MPG"; run; * TAB 27. 3D HISTOGRAM (GTL); * 3D HISTOGRAM CHARTS: EXERCISE 1; ods graphics on / outputfmt=png antialias width=720pt height=390pt; title; footnote; proc sql noprint; create table carSum as select round(horsepower,75) as Horsepower, round(weight,1000) as Weight, avg(mpg_city) as MPG from sashelp.cars group by 1, 2 order by 1, 2; proc template; define statgraph gtl3D; begingraph; entrytitle "Avg MPG (City) by Weight and Horsepower"; layout overlay3d / cube=false zaxisopts=(griddisplay=on) rotate=130; bihistogram3dparm y=weight x=horsepower z=mpg / fillattrs=(color=lightgreen) display=all; endlayout; endgraph; end; proc sgrender data=carSum template=gtl3D; run;