%let name=piemap; filename odsout '.'; %let cmale=cx42C0FB; %let cfemale=hotpink; %let cring=gray33; libname datalib '.' access=readonly ; proc sql; create table my_data as select year, st as st_name, stfips(st) as state, 'dept stores' as store, fem_dept/1000000 as female, mal_dept/1000000 as male from datalib.smm where (year = 1990); quit; run; data my_data; set my_data; value=female+male; run; %let max_area=50; proc sql; /* Find the maximum value */ select max(value) format=comma8.2 into :max_val from my_data; /* Scale data values to dot areas */ create table my_data as select unique st_name, state, female, male, value, (value/&max_val)*&max_area as area from my_data order by value descending; /* so small dots are on top */ /* Get coordinates for the center or each state. */ create table my_data2 as select my_data.*, uscenter.x, uscenter.y from my_data left join mapsgfk.uscenter on my_data.state=uscenter.state having ocean^='Y'; quit; run; /* Create dataset containing the dots */ data anno_dots; length html $300 function color $8; set my_data2; mp=male/value; fp=female/value; html= 'title='||quote( 'State: '||trim(left(fipnamel(state)))||'0D'x|| 'Male Sales (in billion $): '||put(male,comma10.2)|| ' ('||put(mp,percent6.0)||')'||'0D'x|| 'Female Sales (in billion $): '||put(female,comma10.2)||' ('||put(fp,percent6.0)||')'||'0D'x|| '------------------------------------------- '||'0D'x|| 'Total Sales (in billion $): '||put(value,comma10.2) )|| ' href='||quote('#'||trim(left(st_name))); xsys='2'; ysys='2'; hsys='3'; when='a'; /* Calculate the radius (size) for the areas and The smallest pies are pretty tiny, so I'm "cheating" and adding a .2 to the size of all pies. */ size=.2 + sqrt(area/3.14); function='pie'; style='psolid'; percent=female/value*100; rotate=percent*360/100; color="&cfemale"; output; percent=male/value*100; rotate=percent*360/100; color="&cmale"; output; style='pempty'; rotate=360.0; color="&cring"; output; run; data anno_legend; length function text color $8; xsys='3'; ysys='3'; hsys='3'; when='A'; function='pie'; size=1.5; line=0; angle=0.0; rotate=360.0; x=75; style='psolid'; color="&cfemale"; y=83; output; color="&cmale"; y=y-5; output; style='pempty'; color="&cring"; y=83; output; color="&cring"; y=y-5; output; x=75+2; function='LABEL'; color=''; size=3; style=''; position='>'; text='female'; y=83; output; text='male '; y=y-5; output; run; data anno_all; set anno_dots anno_legend; run; /* Create a bunch of tables below the map (one table for each state) with html anchor tags, so I can "drilldown" to them. */ %macro do_table(statecode); %local data_name statecode; ods html anchor="&statecode"; proc sql noprint; create table foo as select * from datalib.smm where st="&statecode"; select unique state into :statename separated by ' ' from foo; quit; run; data foo; set foo; fem_dept=fem_dept*1000; mal_dept=mal_dept*1000; female_percent=fem_dept/(fem_dept+mal_dept); male_percent=mal_dept/(fem_dept+mal_dept); run; title1 ls=2.0 f="albany amt" "Clothing Sales in Department Stores in ... " f="albany amt/bold" "&statename"; goptions xpixels=550 ypixels=250; goptions htitle=8 htext=6; symbol1 c=&cfemale i=join v=dot; symbol2 c=&cmale i=join v=dot; axis1 label=none minor=none order=(0 to 1 by .25) offset=(0,0); axis2 label=none minor=none offset=(0,0); goptions noborder; title2 h=3 ' '; footnote; proc gplot data=foo; format female_percent male_percent percent7.0; note move=(40,75) c=&cfemale "---- Female " c=&cmale "---- Male"; plot female_percent*year=1 male_percent*year=2 / overlay vaxis=axis1 haxis=axis2 noframe vref=.5 cvref=graycc lvref=3 des='' name="plt.&statecode"; run; /* no pagebreak/line between the line graph and the table */ ods html options(pagebreak='no'); title1 h=8pt ' '; title2; proc print data=foo noobs label style(data)={font_size=11pt} style(header)={font_size=11pt}; format fem_dept mal_dept dollar25.0; format female_percent male_percent percent7.0; label year='Year'; label fem_dept='Female'; label mal_dept='Male'; label female_percent='Female %'; label male_percent='Male %'; var year fem_dept mal_dept female_percent male_percent; run; ods html options(pagebreak='yes'); %mend do_table; goptions device=png; goptions xpixels=800 ypixels=600; goptions border; ODS LISTING CLOSE; ODS HTML path=odsout body="&name..htm" (title="Clothing Sales pie-chart Map") style=htmlblue; goptions gunit=pct htitle=5.0 htext=3.2 ftitle="albany amt/bold" ftext="albany amt"; goptions ctext=gray33; title1 ls=1.5 "Clothing Sales in Department Stores"; title2 ls=0.8 "Year = 1990"; footnote1 h=2.3 j=l link="http://www.salesandmarketing.com" ' Data Source: Sales & Marketing Mgmt. Magazine ' j=r link="http://robslink.com/tabis/phd_1991_1996/chapter6.htm#6.2.4" 'NCSU Textile/Apparel Business Information System (TABIS) '; footnote2 h=1 ' '; /* Plot the dots on a US map */ pattern1 v=solid c=white; proc gmap data=mapsgfk.us map=mapsgfk.us anno=anno_all; id state; choro state / levels=1 nolegend coutline=gray99 des='' name="&name"; run; /* Loop through all the states, and call the macro to generate the drilldown graph */ proc sql noprint; create table states as select unique st from datalib.smm; quit; run; data _null_; set states; call execute('%do_table('||st||');'); run; quit; ODS HTML CLOSE; ODS LISTING;