%let name=google; filename odsout '.'; /* SAS/Graph imitation of the google analytics dashboard at: http://www.dnnstuff.com/Portals/8/GoogleAnalytics.jpg */ %let grayback=grayf8; %let grayborder=gray55; %let grayoutline=grayaa; data data1; length html $500; format date date7.; input date date9. Visits Pageviews; myhtml= 'title='||quote( 'Date: '||trim(left(put(date,date9.)))||'0d'x|| 'Visits: '||trim(left(put(visits,comma10.0)))||'0d'x|| 'Pageviews: '||trim(left(put(pageviews,comma10.0)))|| ' ')||' '|| 'href="google.htm"'; datalines; 14nov2007 18 70 15nov2007 118 279 16nov2007 150 519 17nov2007 165 479 18nov2007 120 349 19nov2007 60 224 20nov2007 80 199 ; run; proc sql; select sum(visits) format=comma7.0 into :visits from data1; select sum(pageviews) format=comma7.0 into :pageviews from data1; select sum(pageviews)/sum(visits) format=comma5.2 into :ppv from data1; quit; run; data data2; length html $500; format pct percent9.1; input visitor_type $ 1-20 pct; myhtml= 'title='||quote( trim(left(visitor_type))||': '||trim(left(put(pct,percent8.2)))|| ' ')||' '|| 'href="google.htm"'; datalines; New Visitor .7931 Returning Visitor .2069 ; run; data data4; length html $500; format pct percent9.1; input visitor_source $ 1-20 pct; if pct > .035 then myhtml= 'title='||quote( trim(left(visitor_source))||': '||trim(left(put(pct,percent8.2)))|| ' ')||' '|| 'href="google.htm"'; datalines; google .3292 (direct) .2806 dotnetnuke.com .1083 snocovered.com .0514 cathal.co.uk .0472 foo1 .0333 foo2 .0300 foo3 .0300 foo4 .0300 foo5 .0300 foo6 .0300 ; run; /* For the map ... */ /* I'm just using some long/lat data I had handy, to plot some dots on the map. */ PROC IMPORT OUT=dot_anno DATAFILE= "impact.xls" DBMS=XLS REPLACE; GETNAMES=YES; MIXED=YES; RUN; /* Rename the dbms=xls imported names, so they're the same as the dbms=excel names */ proc datasets; modify dot_anno; rename var4 = diameter__km_; rename var5 = age__ma_; run; proc sort data=dot_anno out=dot_anno; by diameter__km_; run; data dot_anno; set dot_anno; latdeg=0; latdeg=scan(latitude,1,'°'); latmin=0; latmin=scan(scan(latitude,2,'°'),1,"'"); latdir=trim(left(scan(latitude,2,"'"))); longdeg=0; longdeg=scan(longitude,1,'°'); longmin=0; longmin=scan(scan(longitude,2,'°'),1,"'"); longdir=trim(left(scan(longitude,2,"'"))); lat= (latdeg + (latmin/60)); if latdir eq 'S' then lat=lat*-1; long=(longdeg + (longmin/60)); if longdir eq 'W' then long=long*-1; x=atan(1)/45 * long; y=atan(1)/45 * lat; run; data dot_anno; length function style $ 12 color $ 8 position $ 1 text $ 20 html $1024; retain xsys ysys '2' hsys '3' when 'a'; set dot_anno; anno_flag=2; function='pie'; rotate=360; size=.9; position='5'; style='psolid'; color='cxeeb422'; output; /* This is the html title= charttip and href= drilldown for the annotated circle */ length href_string $200; href_string='http://maps.google.com/?ie=UTF8&ll='||trim(left(lat))||','||trim(left(long))|| '&spn=0.074899,0.102654&t=h&z='||trim(left(zoom))||'&om=1'; html='title='||quote( trim(left(name))|| ' ')||' '|| 'href='||quote(href_string); style='pempty'; color="&grayborder"; output; run; proc sql; create table world as select -1*long as x, lat as y, segment, cont as continent, id as country from maps.world where (density<=1) and (id ^= 143); /* leave out antarctica */ create table mydata as select unique continent, country, 1 as color from world; quit; run; data combined; set world dot_anno; run; proc gproject data=combined out=combined dupok eastlong project=gall; id continent country; run; data world dot_anno; set combined; if anno_flag=2 then output dot_anno; else output world; run; /* And this ods style controls the start & end color of the gmap gradient */ %let color1=cxdfffa5; /* light */ %let color2=cx8ba446; /* dark */ proc template; define style styles.robstyle; parent=styles.listing; style twocolorramp / startcolor=&color1 endcolor=&color2; end; run; data backanno; length function $8 style color $15; xsys='3'; ysys='3'; when='b'; color="&grayback"; line=0; style='solid'; x=0; y=0; function='move'; output; x=100; y=90; function='bar'; output; color="&grayborder"; line=0; style='empty'; x=0; y=0; function='move'; output; x=100; y=90; function='bar'; output; run; data plot1title; length function $8 style color $15; xsys='3'; ysys='3'; when='a'; color="&grayback"; line=0; style='solid'; x=5; y=85; function='move'; output; x=75; y=95; function='bar'; output; color="&grayborder"; line=0; style='empty'; x=5; y=85; function='move'; output; x=75; y=95; function='bar'; output; x=42; y=91; function='label'; position='5'; hsys='3'; size=5; color="&grayborder"; style='"arial/bo"'; text='Visit and Pageviews'; output; run; data plot2title; length function $8 style color $15; xsys='3'; ysys='3'; when='a'; color="&grayback"; line=0; style='solid'; x=5; y=85; function='move'; output; x=75; y=95; function='bar'; output; color="&grayborder"; line=0; style='empty'; x=5; y=85; function='move'; output; x=75; y=95; function='bar'; output; x=42; y=91; function='label'; position='5'; hsys='3'; size=5; color="&grayborder"; style='"arial/bo"'; text='Visits by New and Returning'; output; run; data plot3title; length function $8 style color $15; xsys='3'; ysys='3'; when='a'; color="&grayback"; line=0; style='solid'; x=5; y=85; function='move'; output; x=75; y=95; function='bar'; output; color="&grayborder"; line=0; style='empty'; x=5; y=85; function='move'; output; x=75; y=95; function='bar'; output; x=42; y=91; function='label'; position='5'; hsys='3'; size=5; color="&grayborder"; style='"arial/bo"'; text='Geo Map Overlay'; output; run; data plot4title; length function $8 style color $15; xsys='3'; ysys='3'; when='a'; color="&grayback"; line=0; style='solid'; x=5; y=85; function='move'; output; x=75; y=95; function='bar'; output; color="&grayborder"; line=0; style='empty'; x=5; y=85; function='move'; output; x=75; y=95; function='bar'; output; x=42; y=91; function='label'; position='5'; hsys='3'; size=5; color="&grayborder"; style='"arial/bo"'; text='Visits by Source'; output; run; data plot1back; set backanno plot1title; run; data plot2back; set backanno plot2title; run; data plot3back; set backanno plot3title; run; data plot4back; set backanno plot4title; run; goptions device=png; goptions xpixels=350 ypixels=250; goptions cback=white; goptions ftitle="arial/bo" ftext="arial" htitle=12pt htext=8pt; ODS LISTING CLOSE; %let panelcolumns=2; ods tagsets.htmlpanel path="." (url=none) file="&name..htm" (title="SAS/Graph imitation of Google Analytics dashboard") style=robstyle; ods tagsets.htmlpanel event = panel(start); title h=15pct " "; %let color1=cx0198e1; %let color2=cxffa500; symbol1 c=&color1 v=dot h=2.25 i=join; symbol2 c=&color2 v=dot h=2.25 i=join; axis1 label=(f="arial/bold") order=(0 to 200 by 50) value=(c=&color1 f="arial/bo") minor=none offset=(0,0); axis2 label=(f="arial/bold") order=(0 to 600 by 150) value=(c=&color2 f="arial/bo") minor=none offset=(0,0); axis3 label=none minor=(number=1) offset=(4,4); legend1 label=none repeat=1 position=(bottom left) mode=share offset=(2,-4); legend2 label=none repeat=1 position=(bottom left) mode=share offset=(20,-4); title2 "Average: &ppv P / V"; title3 "Pageviews: " c=&color2 "&pageviews"; title4 "Visits: " c=&color1 "&visits"; footnote h=7pct " "; proc gplot data=data1; plot visits*date=1 / anno=plot1back vaxis=axis1 haxis=axis3 autovref cvref=graydd noframe legend=legend1 html=myhtml des="" name="&name"; plot2 pageviews*date=2 / vaxis=axis2 legend=legend2 html=myhtml ; run; legend1 label=none across=3 shape=bar(3,1.5); title2; footnote; pattern1 v=psolid c=cxa4d3ee; pattern2 v=psolid c=cxffc125; proc gchart data=data2; pie3d visitor_type / type=sum sumvar=pct value=outside coutline=&grayborder noheading anno=plot2back legend=legend1 html=myhtml des="" name="&name"; run; pattern1; pattern2; proc gmap data=world map=world all anno=dot_anno; id country; choro country / nolegend coutline=&grayoutline anno=plot3back des="" name="&name"; run; /* pattern1 v=solid c=cxa4d3ee; pattern2 v=solid c=cxffc125; pattern3 v=solid c=cx8fcb8f; pattern4 v=solid c=cxab82ff; pattern5 v=solid c=cxd4ed91; pattern6 v=solid c=cxf08080; */ proc gchart data=data4; pie3d visitor_source / descending type=sum sumvar=pct other=3.5 value=outside coutline=&grayborder noheading anno=plot4back legend=legend1 otherlabel='(other)' html=myhtml des="" name="&name"; run; ods tagsets.htmlpanel event = panel(finish); quit; ods _all_ close;