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

/*
Data copy-n-pasted from ...
http://www.fueleconomy.gov/feg/FEG2000.htm
http://www.fueleconomy.gov/feg/FEG2007_GasolineVehicles.pdf  (June 7, 2007)
   (New mpg standards coming in 2008!)
*/

libname mydata '../democd29';

%let year=2008;



data annoline;
length function color $8;

color='graycc';
xsys='1'; ysys='1'; 
function='move'; x=0; y=0; output;
function='draw'; x=100; y=100; output;

when='a';
color='cx00ff00'; 
xsys='2'; ysys='2';
function='move'; x=30; y=0; output;
function='draw'; x=30; y=30; output;
function='draw'; x=0; y=30; output;

xsys='1'; ysys='1'; 
color='gray99'; position='5';
function='label'; x=93; y=93; text='good'; output;
function='label'; x=7; y=7; text='bad'; output;
run;

goptions device=png;
goptions cback=white;


ODS LISTING CLOSE;
%let panelcolumns=3;
ods tagsets.htmlpanel path="." (url=none) file="&name..htm" 
 (title="2008 Gas Mileage Plots (Created with SAS/Graph)") style=minimal;


goptions xpixels=830 ypixels=80;
goptions ftitle="arial/bo" ftext="arial/bo" htitle=15pt htext=12pt;

title1 "Gas Mileage Plots";
title2 ls=1.5 "year &year";
proc gslide des="" name="&name";
run;



ods tagsets.htmlpanel event = panel(start);

goptions ftitle="arial/bo" ftext="arial" htitle=12pt htext=10pt;
goptions xpixels=284 ypixels=340;

symbol1 color=blue value=circle h=1.6 interpol=none;

axis1 offset=(0,0) order=(0 to 50 by 10) minor=none;
axis2 offset=(0,0) order=(0 to 50 by 10) minor=none;

proc sql;
create table mydata as
select * 
from mydata.mpg_data
where year eq &year;
quit; run;

data mydata; set mydata;
length link $300 href $300;
/* This commented-out drilldown would do a google search for pictures of this car */
/*
 link='http://images.google.com/images?&q='||trim(left(year))||' '||trim(left(manufacturer))||' '||trim(left(model));
*/
/* 
But instead, I this drilldown goes to the html 'anchor' to jump to the table
for that manufacturer, and *then* you can click on the individual cars to 
launch a google search for the picture.
I did it this way for 2 reasons ... 1) to show off the anchor drilldown 
capabilities, and 2) because the plots suffer from plot-marker-stacking,
and I wanted to get users out of the plot and into a list, so they
would be seeing *all* the models (ie, in the table there is no problem
with plot markers "stacking" and obscuring each other.
*/
 link='#'||trim(left(manufacturer));
length myhtml $500;
myhtml=
'title='||quote(
  trim(left(year))||' '||trim(left(manufacturer))||' '||trim(left(model))||'0d'x||
  trim(left(Transmission))||' transmission / '||trim(left(Cylinders))||' cyl / '||trim(left(Engine_Liters))||' liter'||' / '||trim(left(Extra_info))||'0d'x||
  trim(left(put(mpg_hwy,comma5.0)))||' mpg highway  /  '||trim(left(put(mpg_city,comma5.0)))||' mpg city'||
  ' ')||' '||'href='||quote(link);
run;


proc sort data=mydata out=mydata;
by manufacturer descending mpg_hwy;
run;


options nobyline;
title1 h=4 " ";
title2 h=12pt f="arial/bo" "#byval(manufacturer)";

proc gplot data=mydata anno=annoline;
by manufacturer;
label mpg_hwy='Highway';
label mpg_city='City mpg';
plot mpg_hwy*mpg_city=1 / 
 autohref autovref
 chref=graycc cvref=graycc
 vaxis=axis1 haxis=axis2
 nolegend
 html=myhtml
 des="" name="&name";
run;

ods tagsets.htmlpanel event = panel(finish);

quit;
ods _all_ close;



filename odsout '.' mod;
ods listing close;
ODS HTML path=odsout body="&name..htm" style=minimal;


data mydata; set mydata;
length link $300 href $300;
 link='http://images.google.com/images?&q='||trim(left(year))||' '||trim(left(manufacturer))||' '||trim(left(model));
 label link='model';
 href = 'href="' || trim(left(link)) || '"';
 link = '<a ' || trim(href) || ' target="body">' || htmlencode(trim(model)) || '</a>';
run;

%macro do_table(manuf);
ods html anchor="&manuf";
title;
proc report data=mydata (where=(manufacturer="&manuf"));
column manufacturer link mpg_hwy mpg_city transmission engine_liters cylinders extra_info;
run;
%mend;

proc sql; create table foo as select unique manufacturer from mydata; quit; run;
data _null_;
 set foo;
   call execute('%do_table('|| manufacturer ||');');
   call execute('run;');
run;

quit;
ods html close;
