%let name=time_data;
filename odsout '.';

/* Demo showing why not to treat time values as decimal digits...  */

data my_data_numbers;
input team $ 1-6 race1 race2 race3;
average=mean(race1, race2, race3);
datalines;
Team 1 0121.85 0123.57 0127.63
Team 2 0128.31 0129.66 0129.88
Team 3 0140.06 0139.25 0145.16
Team 4 0155.72 0153.38 0206.00
;
run;

data my_data_time;
informat race1 race2 race3 time11.2;
input team $ 1-6 race1 race2 race3;
average=mean(race1, race2, race3);
datalines;
Team 1 00:01:21.85 00:01:23.57 00:01:27.63
Team 2 00:01:28.31 00:01:29.66 00:01:29.88
Team 3 00:01:40.06 00:01:39.25 00:01:45.16
Team 4 00:01:55.72 00:01:53.38 00:02:06.00
;
run;


goptions device=png;
goptions xpixels=700 ypixels=450;
goptions noborder;
 
ODS LISTING CLOSE;
ODS HTML path=odsout body="&name..htm" 
 (title="Time-based Data") 
 style=htmlblue;

goptions gunit=pct htitle=20pt ftitle="albany amt/bold" htext=11pt ftext="albany amt";
goptions ctext=gray33;

title1 h=12pt c=gray33 "(Mis)Treating Time Digits as Decimal Numbers";
proc print data=my_data_numbers noobs
 style(data)={font_size=12pt}
 style(header)={font_size=12pt};
format race1 race2 race3 average z7.2;
var team race1 race2 race3 average;
run;

axis1 label=none style=0 offset=(15,9);
axis2 label=('Numbers') minor=none offset=(0,0);

symbol1 value=circle height=5.0 i=none color=gray77;
symbol2 value=diamondfilled height=5.0 i=none color=red 
 pointlabel=(height=10pt color=red "#average");

title1 ls=1.5 "(Mis)Treating Time Digits as Decimal Numbers";
proc gplot data=my_data_numbers;
format race1 race2 race3 z4.0;
format average z7.2;
plot team*race1=1 team*race2=1 team*race3=1 team*average=2 / overlay
 vaxis=axis1 vreverse haxis=axis2 noframe
 autohref chref=grayaa lhref=33
 autovref cvref=grayaa lvref=33
 des='' name="&name";
run;

data anno_impossible;
length function $8 style $35;
xsys='2'; ysys='1'; when='b';
function='move'; x=160; y=0; output;
function='bar'; x=200; y=100; style='x90'; color='Aff000011'; output;
function='label'; position='5'; color='red'; size=.; style='albany amt/bold'; 
x=180; 
y=61; text='Impossible'; output;
y=y-5.5; text='Times'; output;
output;
run;

proc gplot data=my_data_numbers anno=anno_impossible;
format race1 race2 race3 z4.0;
format average z7.2;
plot team*race1=1 team*race2=1 team*race3=1 team*average=2 / overlay
 vaxis=axis1 vreverse haxis=axis2 noframe
 autohref chref=grayaa lhref=33
 autovref cvref=grayaa lvref=33
 des='' name="&name";
run;


title1 h=12pt c=gray33 "Treating Time Digits as Proper Time Values";
proc print data=my_data_time noobs
 style(data)={font_size=12pt}
 style(header)={font_size=12pt};
format race1 race2 race3 average mmss7.2;
var team race1 race2 race3 average;
run;

axis1 label=none style=0 offset=(15,9);
axis2 label=('Time') order=('00:01:20't to '00:02:10't by '00:00:10't) minor=none offset=(0,0);

title1 ls=1.5 "Treating Time Digits as Proper Time Values";
proc gplot data=my_data_time;
format race1 race2 race3 mmss7.0;
format average mmss7.2;
plot team*race1=1 team*race2=1 team*race3=1 team*average=2 / overlay
 vaxis=axis1 vreverse haxis=axis2 noframe
 autohref chref=grayaa lhref=33
 autovref cvref=grayaa lvref=33
 des='' name="&name";
run;

quit;
ODS HTML CLOSE;
ODS LISTING;
