%let name=drinks; filename odsout '.'; /* SAS imitation of: http://popvssoda.com:2998/countystats/total-county.html http://www.npr.org/sections/thetwo-way/2011/09/01/140110133/soda-or-pop-which-do-you-drink Copy-n-pasted the data for each state into a spreadsheet. https://web.archive.org/web/20081024224840/http://popvssoda.com:2998/countystats/ */ PROC IMPORT OUT=drinks DATAFILE="drinks.xls" DBMS=XLS REPLACE; GETNAMES=YES; RUN; data drinks; set drinks; state=stfips(State_Name); county_name=translate(county_name,'','.'); county_name=translate(county_name,'',"'"); if county_name='Dade' then county_name='MIAMI-DADE'; if county_name='Mountrial' then county_name='Mountrail'; if county_name='Yellowstone National Park (Part)' then county_name='Yellowstone National Park'; if county_name='Skagway-Yakutat-Angoon' then county_name='SKAGWAY-HOONAH-ANGOON'; if county_name='Prince of Wales-Outer Ketchikan' then county_name=' KETCHIKAN GATEWAY'; run; /* Merge in the county fips number */ proc sql; create table drinks as select drinks.*, cntyname.county from drinks left join maps.cntyname on (drinks.state=cntyname.state) and (upcase(compress(drinks.county_name))=compress(cntyname.countynm)); quit; run; /* Turn Pop/Coke/Soda/Other variables into values */ proc sort data=drinks out=drinks; by year state state_name county county_name total; run; proc transpose data=drinks out=drinks; by year state state_name county county_name total; run; proc datasets; modify drinks; rename _name_ = drink_name; rename col1 = drink_votes; run; data drinks; set drinks; if (total ne 0) then do; format drink_percent percent7.1; drink_percent = drink_votes / total; output; end; run; /* Determine the name with the maximum preference in each county */ proc sql; create table drinks as select unique state, state_name, county, county_name, total, drink_name as winner, drink_percent from drinks group by state, county, county_name having drink_percent=max(drink_percent); quit; run; data drinks; set drinks; length pct_range $20 color_group $30; if (drink_percent >= .80) then pct_range='80% - 100%'; else if (drink_percent >= .50) then pct_range='50% - 80%'; else if (drink_percent >= .30) then pct_range='30% - 50%'; else pct_range='???'; color_group = trim(left(winner))||' '||trim(left(pct_range)); if pct_range ne '???' then output; run; /* get rid of the 'Other' categories ... they clutter the graph */ data drinks; set drinks (where=(index(upcase(color_group),'OTHER') eq 0)); length myhtml $300; myhtml= 'title='||quote( put(drink_percent,percent7.2)||' '||trim(left(winner))|| ' (based on '||trim(left(total))||' survey respondents)'||'0d'x || trim(left(county_name))||' county, '||trim(left(state_name)))|| ' href='||quote('https://web.archive.org/web/20081014022025/http://popvssoda.com:2998/countystats/'||trim(left(state_name))||'-stats.html'); run; data mymap; set maps.uscounty; original_order=_n_; run; /* Annotate state outlines on the county map */ proc sort data=mymap out=mymap; by state county original_order; run; proc gremove data=mymap out=outline; by STATE; id state county; run; data outline; set outline; by STATE SEGMENT notsorted; length function color $8; xsys='2'; ysys='2'; when='a'; color='black'; style='mempty'; if first.segment then function='poly'; else function='polycont'; run; goptions device=png; goptions xpixels=950 ypixels=600; goptions border; ODS LISTING CLOSE; ODS HTML path=odsout body="&name..htm" (title="Generic Names for Soft Drinks") style=htmlblue; goptions gunit=pct ftitle="albany amt/bold" ftext="albany amt" htitle=4.5 htext=2.1; goptions ctext=gray33; legend1 position=right across=1 mode=share label=(position=top font="albany amt/bold" j=c 'Most Popular' j=c 'Term Used') shape=bar(.12in,.12in) order=descending value= ( t=1 '80%-100% ' f="albany amt/bold" 'Soda' t=2 '50%-80%' t=3 '30%-50%' t=4 '80%-100% ' f="albany amt/bold" 'Pop' t=5 '50%-80%' t=6 '30%-50%' t=7 '80%-100% ' f="albany amt/bold" 'Coke' t=8 '50%-80%' t=9 '30%-50%' ) offset=(2,3) ; pattern1 v=s c=cxffcccc; pattern2 v=s c=cxff8888; pattern3 v=s c=cxff0000; pattern4 v=s c=cxccccff; pattern5 v=s c=cx8888ff; pattern6 v=s c=cx0000ff; pattern7 v=s c=cxC5E3BF; pattern8 v=s c=cx7BBF6A; pattern9 v=s c=cx397D02; title1 ls=1.5 "What Do You Call Soft Drinks?"; title2 a=-90 h=5pct " "; footnote h=2 ' '; proc gmap data=drinks map=mymap all anno=outline; note move=(1,1.5) c=gray "Survey data courtesy of Alan McConchie - popvssoda.com"; note move=(64.5,1.5) c=gray "Based on 120,464 Respondents (through March 1, 2003)"; id state county; choro color_group / legend=legend1 coutline=gray99 cdefault=white html=myhtml des='' name="&name"; run; quit; ODS HTML CLOSE; ODS LISTING;