%let name=airline_flights; filename odsout '.'; data names; input carrier_code $ 1-2 airline_name $ 4-80; datalines; 9E Pinnacle Airlines AA American Airlines AQ Aloha Airlines AS Alaska Airlines B6 JetBlue Airways CO Continental Airlines DH Atlantic Coast Airlines DL Delta Air Lines EV Atlantic Southeast Airlines F9 Frontier Airlines FL AirTran Airways HA Hawaiian Airlines HP America West Airlines MQ American Eagle NW Northwest Airlines OH Comair OO SkyWest Airlines TW Trans World Airlines TZ ATA Airlines UA United Airlines US US Airways WN Southwest Airlines XE ExpressJet Airlines YV Mesa Airlines ; run; /* rlogin ctnlax01 cd asa sas share_data.sas & */ libname asadata '/users/realliso/asa' server=ctnlax01.shr7 access=readonly; %let year=2008; %let month=12; %macro do_map(carrier); /* %let carrier=DL; */ proc sql noprint; create table flights as select unique UniqueCarrier, origin, dest, count(*) as flight_count from asadata.d&year group by UniqueCarrier, origin, dest having UniqueCarrier="&carrier" and month=&month; /* merge in the lat/long for the origin & destination */ create table flights as select flights.*, locations.lat as origin_lat, locations.long as origin_long from flights left join asadata.locations on (flights.origin=locations.iata); create table flights as select flights.*, locations.lat as dest_lat, locations.long as dest_long from flights left join asadata.locations on (flights.dest=locations.iata); create table anno_titles as select * from names where carrier_code="&carrier"; quit; run; proc rank data=flights out=flights percent; var flight_count; ranks flight_count_rank; run; /* sort by the number of flights, so the lines with the most flights will be drawn last (ie, will be on top & more visible */ proc sort data=flights out=flights; by flight_count; run; data anno_flights; set flights; xsys='2'; ysys='2'; when='a'; flag=1; length color $8; if flight_count_rank > 95 then color='cx60AFFE'; /* blue */ else if flight_count_rank > 75 then color='cxffffff'; else if flight_count_rank > 50 then color='cxf0f0f0'; else if flight_count_rank > 25 then color='cxd0d0d0'; else color='cxa0a0a0'; x=origin_long; y=origin_lat; function='move'; output; x=dest_long; y=dest_lat; function='draw'; size=.001; output; run; /* convert degrees to radians */ data anno_flights; set anno_flights; x=atan(1)/45 * x *-1; y=atan(1)/45 * y; run; /* combine annotate & map, gproject together, then separate again */ data mymap; set maps.namerica (where=(density<=2 and lat<=1.3 and long>0)); x=long; y=lat; run; data combined; set mymap anno_flights; run; proc gproject project=eckert1 data=combined out=combined dupok nodateline longmax=166 longmin=40 latmax=73 latmin=10 ; id id; run; data mymap anno_flights; set combined; if flag=1 then output anno_flights; else output mymap; run; /* Annotate the titles at the bottom of the map */ data anno_titles; set anno_titles; length function $8 text $100; xsys='3'; ysys='3'; when='a'; function='label'; y=3; x=3; position='6'; text=trim(left(airline_name))||" (&month/&year)"; output; html='http://www.sas.com/technologies/bi/query_reporting/graph/index.html'; x=97; position='4'; text='SAS/Graph Map'; output; run; goptions dev=png xpixels=1000 ypixels=700; ODS LISTING CLOSE; ODS HTML path=odsout body="&name._&carrier..htm" (title="&carrier Flights Map") style=minimal; goptions noborder cback=black; goptions htitle=18pt htext=14pt ftitle="albany amt/bo" ftext="albany amt/bold" ctext=white; pattern1 v=solid c=gray33; title1; footnote1; proc gmap data=mymap map=mymap anno=anno_titles; id id; choro id / levels=1 coutline=black nolegend anno=anno_flights des='' name="&name._&carrier"; run; quit; ods html close; ods listing; %mend do_map; proc sql; create table carriers as select unique UniqueCarrier from asadata.d&year where month=&month; quit; run; data _null_; set carriers; call execute('%do_map('|| UniqueCarrier ||');'); call execute('run;'); run; /* %do_map(YV); */