%let name=how_to_spell_searches; /* %let rc=%sysfunc(dlgcdir('c:\someplace\public_html')); */ filename odsout '.'; /* Using data from: https://twitter.com/GoogleTrends/status/735828896185081858 */ data my_data; length statecode $2 word $20; input statecode word; datalines; AK Hawaii HI Boutineer TX Niece FL Tomorrow GA Appreciate CA Desert OR Definitely WA Pneumonia ID Desert MT Vacuum WY Ornery NV Cousin UT Leprechaun NM Neighbor AZ Diarrhea CO Beautiful OK Gray KS Schedule NE Guarantee SD Gray ND Attitude MN Broccoli IA Maintenance MO Pneumonia AR Leprechaun LA Definitely WI Vacuum MI Gray IL Appreciate IN Desert OH Banana MS Sergeant AL Tongue TN Courtesy KY Maintenance SC Convenience NC Pneumonia VA Cancelled WV Giraffe MD Cancelled PA Cancelled DE Neighbor NJ February NY Beautiful CT Desert RI Cancelled MA Massachusetts VT Possible NH Diarrhea ME Vacuum ; run; proc sql; create table my_data as select *, count(*) as count from my_data group by word; quit; run; data my_data; set my_data; length count_text $50; if count=1 then count_text=trim(left(count))||' state'; else count_text=trim(left(count))||' states'; length my_html $300; my_html= 'title='||quote("People in "||trim(left(fipnamel(stfips(statecode))))|| " most often searched for"||'0d'x|| "'How to spell "||trim(left(word))||"'")|| ' href='||quote('https://www.google.com/search?q=how+to+spell+'||trim(left(word))); run; /* Annotate the labels on the map */ data anno_labels; set mapsgfk.uscenter(where=(statecode not in ('DC'))); original_order=_n_; run; proc sql noprint; create table anno_labels as select anno_labels.*, my_data.* from anno_labels left join my_data on anno_labels.statecode=my_data.statecode; quit; run; proc sort data=anno_labels out=anno_labels; by original_order; run; data anno_labels; set anno_labels; length function color $8 html $300; retain flag 0; xsys='2'; ysys='2'; hsys='3'; when='a'; function='label'; html=my_html; style="albany amt/bold"; size=1.9; text=trim(left(word)); if ocean^='Y' and flag^=1 then do; color='white'; if statecode in ('FL' 'HI') then color='gray88'; position='5'; output; end; else if ocean='Y' then do; color='gray88'; position='6'; output; function='move'; output; flag=1; end; else if flag=1 then do; color='gray33'; function='draw'; size=.25; output; flag=0; end; run; data anno_labels; set anno_labels; if statecode='LA' then do; x=x+.01; y=y-.008; end; if statecode='KY' then do; x=x-.015; y=y-.007; end; if statecode='NY' then y=y-.005; if statecode='GA' then x=x+.005; run; goptions device=png; goptions xpixels=1000 ypixels=650; goptions border; ODS LISTING CLOSE; ODS HTML path=odsout body="&name..htm" (title="Most common 'how to spell' words") style=htmlblue; goptions gunit=pct ftitle='albany amt/bold' ftext='albany amt' htitle=5.0 htext=2.25; goptions ctext=gray33; title1 ls=1.5 "Spelling in the US..."; title2 a=90 h=.4 ' '; title3 a=-90 h=9 ' '; pattern1 v=s c=cxfebb11; pattern2 v=s c=cx4a72b8; pattern3 v=s c=cxa64d9a; pattern4 v=s c=cxeb2449; legend1 position=(bottom right inside) across=1 order=descending label=none shape=bar(.15in,.15in) offset=(0,15); proc gmap data=my_data map=mapsgfk.us all anno=anno_labels; id statecode; note move=(30,88) h=2.9 'Top searched "how to spell" word in each state'; note move=(50,3) link='https://twitter.com/GoogleTrends/status/735828896185081858' c=gray "Data source: Google Trends, 2016"; choro count_text / midpoints = '1 state' '2 states' '3 states' '4 states' /* discrete midpoints = 1 2 3 4 */ coutline=grayee legend=legend1 html=my_html des='' name="&name"; run; data my_data; set my_data; length colorvar $20; if count_text='1 state' then colorvar=' unique'; else colorvar=word; run; data anno_labels; set anno_labels; if count_text='1 state' and function='label' then color='gray88'; run; goptions reset=pattern; pattern1 v=s c=cxfffcf1 repeat=1; ods html anchor='version2'; proc gmap data=my_data map=mapsgfk.us all anno=anno_labels; id statecode; note move=(30,88) h=2.9 'Top searched "how to spell" word in each state'; note move=(50,3) link='https://twitter.com/GoogleTrends/status/735828896185081858' c=gray "Data source: Google Trends, 2016"; choro colorvar / nolegend coutline=graydd legend=legend1 html=my_html des='' name="&name"; run; quit; ODS HTML CLOSE; ODS LISTING;