%let name=halloween_child_fatalities; filename odsout '.'; /* Inspired by this graph: http://www.bestplaces.net/docs/studies/halloween_deadliest_day_2014.aspx http://www.bertsperling.com/wp-content/uploads/Halloween-graph-deadliest-day.png Also, similar to graphs on p. 15 of this report: http://www-nrd.nhtsa.dot.gov/Pubs/809855.pdf */ /* Used Google Chrome browser (won't work in IE) Went to http://www-fars.nhtsa.dot.gov/ Clicked 'Query FARS Data' tab Selected latest year (2013) in the pulldown near top/right, and clicked 'Submit' button Selected Option 2 (crash non-occupant), and clicked the 'Submit' button Check-boxed to get these fields Number of Fatalities in Crash Crash Date Crash Time Age Case Listing Additionally checked Crash Date, Number of Fatalities in Crash, and Age Export txt Saved as non_occupant_fatalities_yyyy.txt */ %macro readyear(year); filename file&year "non_occupant_fatalities_&year..txt"; data data&year (drop = obs); infile file&year lrecl=80 pad firstobs=3 delimiter='09'x; input obs statenum casenum accdate acctime numfatal age; year=&year; format fakedate monname3.; date=input(put(accdate,z8.),mmddyy8.); fakedate=input(substr(put(accdate,z8.),1,4)||'2013',mmddyy8.); if numfatal^=-1 and age^=-1 and fakedate^=. then output; run; %mend; %readyear(2013); %readyear(2012); %readyear(2011); %readyear(2010); data all_data; set data2013 data2012 data2011 data2010 ; /* to summarize & plot all the values together, I make a 'fakedate' where they all look like 2013 dates. Of course, this ignores the Feb 29 leapyear issue ... but close enough! */ if fakedate='31oct2013'd then colorvar=2; else colorvar=1; if fakedate^=. then output; run; %let age=18; proc sql noprint; create table child_summary as select unique fakedate, colorvar, sum(numfatal) as fatalities from all_data where age<=&age group by fakedate; create table adult_summary as select unique fakedate, colorvar, sum(numfatal) as fatalities from all_data where age>&age group by fakedate; quit; run; goptions device=png; goptions xpixels=850 ypixels=500; ODS LISTING CLOSE; ODS HTML path=odsout body="&name..htm" (title="Fatal Traffic Accidents Per Day in the United States") style=htmlblue; goptions gunit=pct htitle=4.5 htext=2.8 ftitle="albany amt/bold" ftext="albany amt"; goptions ctext=gray33; axis1 label=none order=('01jan2013'd to '01jan2014'd by month) minor=none value=(t=13 ''); axis2 label=none style=0 order=(0 to 25 by 5) major=none minor=none offset=(0,0); symbol1 mode=include value=none interpol=needle color=gray77; symbol2 mode=include value=none interpol=needle width=2 color=red; title1 ls=1.5 "Child Pedestrian Fatalities per Day (2010-2013)"; footnote1 j=l move=(+2,+0) "Total number of non-occupant (pedestrian, etc) traffic fatalities per day, for victims age &age and under, years 2010-2013"; footnote2 j=l move=(+2,+0) link='http://www-fars.nhtsa.dot.gov//QueryTool/QuerySection/SelectYear.aspx' "Data source: National Highway Traffic Safety Administration (NHTSA) Fatality Analysis Reporting System (FARS)"; proc gplot data=child_summary; note move=(7,82) "Halloween is marked with a " c=red "red bar"; plot fatalities*fakedate=colorvar / nolegend vaxis=axis2 haxis=axis1 vzero noframe autovref cvref=gray77 lvref=33 des='' name="&name"; run; axis3 label=none style=0 order=(0 to 120 by 20) major=none minor=none offset=(0,0); title1 ls=1.5 "Adult Pedestrian Fatalities per Day (2010-2013)"; footnote1 j=l move=(+3,+0) "Total number of non-occupant (pedestrian, etc) traffic fatalities per day, for victims over age &age, years 2010-2013"; footnote2 j=l move=(+3,+0) link='http://www-fars.nhtsa.dot.gov//QueryTool/QuerySection/SelectYear.aspx' "Data source: National Highway Traffic Safety Administration (NHTSA) Fatality Analysis Reporting System (FARS)"; proc gplot data=adult_summary; note move=(7,82) "Halloween is marked with a " c=red "red bar"; plot fatalities*fakedate=colorvar / nolegend vaxis=axis3 haxis=axis1 vzero noframe autovref cvref=gray77 lvref=33 des='' name="&name"; run; quit; ODS HTML CLOSE; ODS LISTING;