%let gpath='.'; %let dpi=200; ods html close; ods listing gpath=&gpath image_dpi=&dpi; /*--Render a basic box plot and save the graph data--*/ ods output sgplot=boxdata(rename=(BOX_MPG_CITY_X_TYPE_SORTORDER__X=X BOX_MPG_CITY_X_TYPE_SORTORDER__Y=Y BOX_MPG_CITY_X_TYPE_SORTORDER_ST=Stat)); ods graphics / reset width=5in height=3in imagename='Box'; title 'Mileage by Type'; proc sgplot data=sashelp.cars; vbox mpg_city / category=type; xaxis display=(nolabel); run; /*--Find largest N value--*/ data null; retain maxN 0; set boxdata end=last; if stat eq 'N' then maxN=max(maxN, y); if last then call symput("MaxN", maxN); run; /*--Sort by X--*/ proc sort data=boxdata out=boxdata; by x; run; /*--Add a row for each category with stat=BoxWidth proportional to N--*/ data boxDataWidth; drop boxwidth; set boxdata(where=(x ne '')); by x; if stat eq 'N' then do; N=y; output; boxwidth=0.05+ 0.6* n/&MaxN; stat='BOXWIDTH'; y=boxwidth; output; end; else output; run; /*--Define a Template for box Plot--*/ proc template; define statgraph BoxWidth; begingraph; entrytitle 'Mileage by Type'; entrytitle 'Box Width is Proportional to N' / textattrs=(size=8); layout overlay / xaxisopts=(display=(ticks tickvalues)); boxplotparm x=x y=y stat=stat; scatterplot x=x y=eval(y*0+5) / markercharacter=n; endlayout; endgraph; end; run; /*--Render the graph--*/ ods graphics / reset width=5in height=3in imagename='BoxWidth'; proc sgrender data=boxdataWidth template=BoxWidth; format n 3.0; run;