%let name=fema_disaster_declarations_maps; filename odsout '.'; /* Creating a map similar to: http://oldsite.osogrande.com/images/disastermap1.png Using data from: http://www.fema.gov/disasters/grid/state */ libname robsdata '.'; data my_data; set robsdata.femadeclarations (where=(Incident_Begin_Date>='01jan1965'd and Incident_Begin_Date<'01jan2013'd)); declaration_count=1; year=year(Incident_Begin_Date); run; proc sql noprint; create table my_data as select *, sum(declaration_count) format=comma20.0 as year_count from my_data group by year; quit; run; libname robsmaps '../democd97'; data my_map; set robsmaps.uscounty (where=(density<=1) rename=(state=state_fips)); state=fipstate(state_fips); run; /* Annotate state outlines on the county map */ data my_map; set my_map; original_order=_n_; run; proc sort data=my_map out=my_map; by state county original_order; run; proc gremove data=my_map 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='gray33'; style='mempty'; if first.segment then function='poly'; else function='polycont'; run; %macro do_map(year); ods html anchor="map_&year"; data tempdata; set my_data (where=(year=&year)); run; proc sql noprint; create table tempdata as select unique year, year_count, state, county, sum(declaration_count) as count from tempdata group by state, county; create table alt_data as select unique state, incident_type from my_data where year=&year order by state; quit; run; data alt_data; set alt_data; retain html; length html $500; by state; if first.state then do; html='title="'||trim(left(fipnamel(stfips(state))))||': '||'0d'x||'----------'||'0d'x; end; html=trim(left(html))||trim(left(incident_type)); if not last.state then do; html=trim(left(html))||', '||'0d'x; end; if last.state then do; html=trim(left(html))||'"'; output; end; run; data alt_data; set alt_data; html=trim(left(html))|| ' href='||quote('fema_disaster_declarations_bars.htm#bar_'||trim(left("&year"))); run; proc sql noprint; create table temp_outline as select outline.*, alt_data.html from outline left join alt_data on outline.state=alt_data.state order by original_order; quit; run; data tempdata; set tempdata; bucket=' '; if count=1 then bucket='a'; else if count=2 then bucket='b'; else if count=3 then bucket='c'; else if count=4 then bucket='d'; else if count>=5 then bucket='e'; run; pattern1 v=s c=cxFED976; pattern2 v=s c=cxFEB24C; pattern3 v=s c=cxFD8D3C; pattern4 v=s c=cxF03B20; pattern5 v=s c=cxBD0026; legend2 label=none value=('1' '2' '3' '4' '5+') shape=bar(.15in,.15in); options nobyline; title1 link="http://www.fema.gov/disasters/grid/year/&year?field_disaster_type_term_tid_1=All" ls=1.5 "#byval(year_count) FEMA Disaster Declarations (&year)"; proc gmap data=tempdata map=my_map all anno=temp_outline; by year_count; id state county; choro bucket / midpoints = 'a' 'b' 'c' 'd' 'e' coutline=graydd cdefault=cornsilk legend=legend2 des='' name="&name._&year"; run; /* proc print data=alt_data; run; */ %mend; goptions device=png; goptions xpixels=950 ypixels=600; goptions border; ODS LISTING CLOSE; ODS HTML path=odsout body="&name..htm" (title="Fema Disaster Declarations") style=htmlblue; goptions gunit=pct ftitle="albany amt/bold" ftext="albany amt" htitle=4.5 htext=2.1; legend1 label=none shape=bar(.15in,.15in); proc sql noprint; select sum(declaration_count) format=comma20.0 into :count separated by ' ' from my_data; quit; run; data outline; set outline; length html $500; html='href="fema_disaster_declarations_bars.htm"'; run; title1 link="http://www.fema.gov/disasters/grid/year" ls=1.5 "&count FEMA Disaster Declarations (1965-2012)"; proc gmap data=my_data map=my_map all anno=outline; id state county; choro declaration_count / stat=freq levels=5 coutline=gray99 cdefault=cornsilk legend=legend1 des='' name="&name"; run; data outline; set outline (drop=html); original_order=_n_; color='gray77'; run; proc sql noprint; create table foo as select unique year from my_data; quit; run; data _null_; set foo; call execute('%do_map('|| year ||');'); run; /* */ quit; ODS HTML CLOSE; ODS LISTING;