%let name=kipchoge_2hr_marathon; /* Set your current-working-directory (to read/write files), if you need to ... %let rc=%sysfunc(dlgcdir('c:\someplace\public_html')); */ filename odsout '.'; /* Downloaded Boston Marathon data from here: https://github.com/llimllib/bostonmarathon Creating a graph similar to the one here: https://www.reddit.com/r/dataisbeautiful/comments/di597g/eliud_kipchoge_vs_the_boston_marathon_oc/ */ libname race_lib 'D:\Public\Boston_Marathon\'; /* libname race_lib '\\l7a695.na.sas.com\Public\Boston_Marathon\'; */ data my_data; set race_lib.boston_marathon (where=(year=2014 and bib_num^=.)); run; data my_data; set my_data; official_rounded=round(official); /* convert minutes to hours */ official_rounded=official_rounded*60; if official_rounded<="6:00:00"t then output; run; proc sql noprint; create table plot_data as select unique official_rounded, count(*) as count from my_data group by official_rounded; quit; run; data anno_label; length label $300 function x1space y1space anchor $50; layer="front"; function="text"; textcolor="red"; textweight="bold"; textsize=14; anchor="bottom"; justify="center"; width=11; widthunit="percent"; label="Eliud's Time 1:59:40"; x1space='datapercent'; y1space='datapercent'; x1=90; y1=20; output; function="arrow"; linecolor="red"; linethickness=2; shape="filled"; x2space='datapercent'; y2space='datapercent'; x2=100; y2=0; output; run; ODS LISTING CLOSE; ODS HTML path=odsout body="&name..htm" (title="Eliud Kipchoge's 2hr marathon, versus Boston Marathon times") style=htmlblue; ods graphics / noscale /* if you don't use this option, the text will be resized */ imagemap tipmax=1000 imagefmt=png imagename="&name" width=825px height=600px noborder; /* proc sgplot data=my_data; label official='Time to finish marathon (minutes)'; histogram official; xaxis reverse; run; */ /* ods graphics / width=815px height=600px; data my_data; set my_data; official_rounded=round(official); run; proc sql noprint; create table plot_data as select unique official_rounded, count(*) as count from my_data group by official_rounded; quit; run; proc sgplot data=plot_data ; label count='Number of runners finishing in that time'; label official_rounded='Time to finish marathon (rounded to the nearest minute)'; needle x=official_rounded y=count / lineattrs=(thickness=3px color=cx5994c8); xaxis values=(120 to 360 by 60) reverse; yaxis display=(noline) values=(0 to 350 by 50); run; */ title1 h=18pt color=gray33 "Eliud Kipchoge's 1:59:40 marathon (26.2 miles)"; title2 h=18pt color=gray33 "Versus typical Boston Marathon times (2014)"; title3 h=3pt 'a0'x; proc sgplot data=plot_data noborder sganno=anno_label; format official_rounded hhmm.; label count='Number of runners finishing in that time'; label official_rounded='Time to finish marathon (rounded to the nearest minute)'; needle x=official_rounded y=count / lineattrs=(thickness=3px color=cx5994c8); xaxis values=('02:00:00't to '06:00:00't by '01:00:00't) valueattrs=(color=gray33 size=11pt) labelattrs=(color=gray33 size=11pt) reverse offsetmin=0 offsetmax=0 ; yaxis display=(noline) values=(0 to 350 by 50) valueattrs=(color=gray33 size=11pt) labelattrs=(color=gray33 size=11pt) offsetmin=0 offsetmax=0 ; refline "02:00:00"t "03:00:00"t "04:00:00"t "05:00:00"t "06:00:00"t / axis=x lineattrs=(color=gray33); run; quit; ODS HTML CLOSE; ODS LISTING;