%let name=drug_deaths_anim; filename odsout '.'; /* csv data: http://blogs.cdc.gov/nchs-data-visualization/drug-poisoning-mortality/ https://data.cdc.gov/api/views/pbkm-d27e/rows.csv?accessType=DOWNLOAD http://makingnoiseinthesouth.com/index.php/2016/03/01/left-behind-communities-overlooked-by-response-to-opioid-epidemic-from-the-fix/ Better map: http://learning.blogs.nytimes.com/2016/01/20/news-qs-how-the-epidemic-of-drug-overdose-deaths-ripples-across-america/ */ PROC IMPORT OUT=my_data DATAFILE="D:\Public\NCHS\NCHS_-_Drug_Poisoning_Mortality__County_Trends__United_States__2002_2014.csv" DBMS=CSV REPLACE; GETNAMES=YES; DATAROW=2; guessingrows=2000; RUN; data my_data; set my_data (rename=(state=state_name county=county_name Estimated_Age_adjusted_Death_Ra=rate)); length id $8; id='US-'||put(fips,z5.); /* if you want to use with mapsgfk.us_counties */ state=.; state=fips_state; county=.; county=substr(id,6); legend_order=99; if rate='0.0-2.0' then legend_order=1; if rate='2.1-4.0' then legend_order=1; if rate='4.1-6.0' then legend_order=2; if rate='6.1-8.0' then legend_order=2; if rate='8.1-10.0' then legend_order=3; if rate='10.1-12.0' then legend_order=3; if rate='12.1-14.0' then legend_order=4; if rate='14.1-16.0' then legend_order=4; if rate='16.1-18.0' then legend_order=5; if rate='18.1-20.0' then legend_order=5; if rate='>20' then legend_order=6; length rate2 $50; if legend_order=1 then rate2='0 - 4'; if legend_order=2 then rate2='4.1 - 8'; if legend_order=3 then rate2='8.1 - 12'; if legend_order=4 then rate2='12.1 - 16'; if legend_order=5 then rate2='16.1 - 20'; if legend_order=6 then rate2='> 20'; /* length my_html $300; my_html='title='||quote( trim(left(county_name))||'0d'x|| trim(left(rate2)) ); run; */ proc sort data=my_data out=my_data; by year; run; proc sql noprint; create table control as select unique legend_order as start, rate2 as label from my_data; quit; run; data control; set control; fmtname='ratefmt'; type='N'; run; proc format lib=work cntlin=control; run; data my_map; set maps.uscounty; run; proc gremove data=my_map out=anno_outline; by state; id county; run; data anno_outline; set anno_outline; by state segment notsorted; length function $8 color $8; color='gray11'; style='mempty'; when='a'; xsys='2'; ysys='2'; if first.SEGMENT then FUNCTION='Poly'; else function='Polycont'; run; options dev=sasprtc printerpath=gif animduration=.4 animloop=5 animoverlay=no animate=start center nobyline; /* goptions device=png; */ goptions xpixels=900 ypixels=600; goptions border; ODS LISTING CLOSE; ODS html path=odsout body="&name..htm" (title="Drug Deaths in US") style=htmlblue; goptions gunit=pct htitle=4.3 htext=2.2 ftitle='albany amt/bold' ftext='albany amt'; pattern1 v=s c=cxfef0d9; pattern2 v=s c=cxfdd49e; pattern3 v=s c=cxfdbb84; pattern4 v=s c=cxfc8d59; pattern5 v=s c=cxef6548; pattern6 v=s c=cxd7301f; legend1 label=(position=top j=c 'Deaths per' j=c '100,000') position=(right middle) across=1 order=descending value=(justify=center) shape=bar(.15in,.15in) mode=share offset=(-1,-20); options nobyline; title1 ls=1.5 "Death Rate from Drug Poisioning / Overdose"; footnote link='https://data.cdc.gov/api/views/pbkm-d27e/rows.csv?accessType=DOWNLOAD' c=gray 'Data Source: CDC (Age Adjusted Death Rate)'; proc gmap data=my_data map=my_map all anno=anno_outline; by year; format legend_order ratefmt.; note move=(72,80) font='albany amt/bold' height=7 "#byval(year)"; id state county; choro legend_order / discrete legend=legend1 coutline=grayaa des='' name="&name"; run; /* do a few extra year=2014 at the end, so the animation will seem to 'pause' on that year before re-starting. */ proc gmap data=my_data (where=(year=2014)) map=my_map all anno=anno_outline; by year; format legend_order ratefmt.; note move=(72,80) font='albany amt/bold' height=7 "#byval(year)"; id state county; choro legend_order / discrete legend=legend1 coutline=grayaa des='' name="&name"; run; run; run; run; run; quit; ODS HTML CLOSE; ODS LISTING;