%let name=measles_prediction_2019; filename odsout '.'; /* Creating a better version of map: https://ksltv.com/wp-content/uploads/2019/05/PIIS1473309919302312.pdf Using data from: https://fivethirtyeight.com/features/we-can-predict-where-measles-will-happen-why-dont-we/ */ data my_data; length county_name $50 state_name $50 cases_flag $1 position $1; infile datalines dlm='09'x; input rank county_name state_name cases_flag position x_offset y_offset; datalines; 1 Cook Illinois Y 2 -.01 .01 2 Los Angeles California Y 2 -.03 .01 3 Miami-Dade Florida N > .015 .00 4 Queens New York Y > .015 .00 5 King Washington Y > .015 .00 6 Maricopa Arizona N 2 .00 .01 7 Broward Florida Y 3 .01 .00 8 Clark Nevada Y 2 -.003 .015 9 Harris Texas Y 2 .01 .01 10 Honolulu Hawaii N 2 .00 .01 11 Wayne Michigan Y 2 .00 .01 12 Tarrant Texas Y 2 .00 .01 13 Multnomah Oregon Y 8 .00 -.003 14 Orange Florida N 2 .01 .01 15 Essex New Jersey Y a -.013 .00 16 Denver Colorado Y 2 .00 .01 17 Hillsborough Florida N < -.015 .00 18 San Mateo California Y 2 .00 .01 19 Salt Lake Utah N 2 .00 .01 20 Suffolk Massachusetts N 2 .00 .01 21 Clayton Georgia N 2 .00 .01 22 Travis Texas N 2 -.01 .01 23 Hennepin Minnesota N 2 .00 .01 24 Loudoun Virginia Y 2 .00 .01 25 San Diego California N 8 -.02 -.005 ; run; proc sql noprint; /* merge in the 2-character statecode */ create table my_data as select unique my_data.*, us_states_attr.statecode from my_data left join mapsgfk.us_states_attr on my_data.state_name=us_states_attr.idname; /* merge in the numeric county fips code */ create table my_data as select unique my_data.*, us_counties_attr.county from my_data left join mapsgfk.us_counties_attr on my_data.state_name=us_counties_attr.id1name and my_data.county_name=us_counties_attr.idname ; quit; run; data my_data; set my_data; length my_html $300; my_html= 'title='||quote(trim(left(county_name))||' County, '||trim(left(statecode))||'0d'x|| 'Rank = #'||trim(left(rank)))|| ' href='||quote('https://www.google.com/search?q=2019+measles+'|| trim(left(county_name))||' county, '||trim(left(statecode))); run; libname robsmaps '../democd97'; data my_map; set robsmaps.uscounty (where=(density<=1)); original_order=_n_; run; /* No sense finding the centroid of every county, so just do it for the 25 of interest... */ proc sql noprint; create table subset_map as select my_data.statecode, my_data.county, my_map.x, my_map.y, my_map.segment from my_data left join my_map on my_map.statecode=my_data.statecode and my_map.county=my_data.county order by statecode, county, original_order; quit; run; %annomac; %centroid(subset_map,county_centroids,statecode county,segonly=1); /* Now, merge in the centroids with the rest of the data ... */ proc sql noprint; create table my_data as select unique my_data.*, county_centroids.x, county_centroids.y from my_data left join county_centroids on my_data.statecode=county_centroids.statecode and my_data.county=county_centroids.county; quit; run; data anno_markers; set my_data; length function $8 color $12 style $35 text $100 html $300; xsys='2'; ysys='2'; hsys='3'; when='a'; function='pie'; style='pempty'; rotate=360; color='red'; size=2.0; output; size=2.2; output; function='label'; color='black'; size=2.0; rotate=.; style='albany amt'; html=my_html; x=x+x_offset; y=y+y_offset; text=trim(left(county_name))||', '||trim(left(statecode)); output; run; proc gremove data=my_map out=anno_outline; by statecode notsorted; id county; run; data anno_outline; set anno_outline; length function $8; by statecode notsorted segment; xsys='2'; ysys='2'; hsys='3'; when='a'; color="graybb"; size=1.0; if first.segment or (lag(x)=. and lag(y)=.) then function='poly'; else function='polycont'; if x^=. and y^=. then output; run; goptions device=png; goptions xpixels=900 ypixels=600; goptions border; ODS LISTING CLOSE; ODS html path=odsout body="&name..htm" (title="US Measles Prediction 2019") options(pagebreak='no') style=htmlblue; goptions gunit=pct ftitle='albany amt' ftext='albany amt' htitle=5.0 htext=3.5; goptions ctext=gray33; pattern1 v=s c=pink; title1 ls=1.5 "Predicted highest risk of measles in 2019"; footnote c=gray99 h=2.5 'Data sources: ' link='https://ksltv.com/wp-content/uploads/2019/05/PIIS1473309919302312.pdf' 'The Lancet, and ' link='https://fivethirtyeight.com/features/we-can-predict-where-measles-will-happen-why-dont-we/' 'FiveThirtyEight.com'; proc gmap data=my_data map=my_map all anno=anno_outline; id statecode county; note move=(40,88) c=gray33 h=3.5 "Top 25 US Counties"; choro rank / levels=1 nolegend anno=anno_markers coutline=gray33 cempty=grayee html=my_html des='' name="&name"; run; quit; ODS HTML CLOSE; ODS LISTING;