SAS中文论坛

 找回密码
 立即注册

扫一扫,访问微社区

查看: 1731|回复: 1
打印 上一主题 下一主题

SAS/Graph iPhone Dashboard

[复制链接]

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
楼主
 楼主| 发表于 2012-8-18 14:39:53 | 只看该作者

SAS/Graph iPhone Dashboard

[code:3seftokx]%let name=iPhone_dashboard;
filename odsout '.';

/* Text shades */
%let dark=gray66;
%let medium=gray44;
%let darker=gray11;

%let ci=99%;      /* top/right of graph */
%let total=.75;   /* location of dashed refline */
%let control=1.0; /* location of solid refline */

%let badcolor=cx777777;

/*
http://sww.sas.com/~realliso/democd38/iPhone_dashboard.htm
*/

data mydata;
length color1 color2 color3 $8;
input measure $ 1-30 bar mid1 mid2 color1 color2 color3 cv
/* These are values to draw the sparkline - these are normalized/scaled from 0-100 */
line1 line2 line3 line4 line5 line6 line7 line8 line9 line10 line11 line12;
bar=bar/100;
mid1=mid1/100;  /* end of first range in bullet graph background */
mid2=mid2/100;  /* end of second range in bullet graph background */
format bar percent7.0;
datalines;
                                .     .   .    cxffffff cxffffff cxffffff    .  . . . . . . . . . . . .
Financial                       .     .   .    cxffffff cxffffff cxffffff    .  . . . . . . . . . . . .
$ Revenues in mil               101.4  80 100  cx777777 cxbbbbbb cxdddddd  17.58 85 85 92 50 78 85 80 10 80 80 90 92
$ Expenses in mil               105.1 100 120  cxdddddd cxbbbbbb cx777777  12.33 90 80 85 15 80 70 65 70 75 80 85 92
$ Profits in mil                126.7  75 100  cx777777 cxbbbbbb cxdddddd   5.25 65 90 90 10 92 60 60 65 60 75 65 60
Market Share in %               100.0  75 100  cx777777 cxbbbbbb cxdddddd  43.00 20 85 85 85 20 15 15 15 15 20 25 25
Flight Statistics               .     .   .    cxffffff cxffffff cxffffff    .  . . . . . . . . . . . .
Flights                         100.9  75 100  cx777777 cxbbbbbb cxdddddd  45.10 85 85 50 10 92 90 90 90 90 90 92 92
Passengers in K                 100.9  75 100  cx777777 cxbbbbbb cxdddddd  60.40 85 85 50  5 92 80 70 80 85 87 90 93
Miles in K                      114.6  75 100  cx777777 cxbbbbbb cxdddddd  34.80 80 80 60 10 92 90 94 96 93 96 97 96
Passenger Miles                 101.2  75 100  cx777777 cxbbbbbb cxdddddd  31.50 75 75 10 50 85 60 70 75 78 80 84 88
Cancelled Flights                83.9 100 120  cxdddddd cxbbbbbb cx777777   8.00 10 20 15 80 80 60 20  5 50 50 40 40
Late Arrivals                   178.6 100 120  cxdddddd cxbbbbbb cx777777  65.00 30 30 80 15 90 85 65 55 45 45 40 20
# of Minutes Late               186.4 100 120  cxdddddd cxbbbbbb cx777777 128.60 15 25 20 90 70 75 45 30 35 40 20 10
$ Fuel Costs                    134.7 100 120  cxdddddd cxbbbbbb cx777777  13.50 85 85  5 80 60 62 70 70 60 70 80 90
Customer                        .     .   .    cxffffff cxffffff cxffffff    .  . . . . . . . . . . . .
Customer Satisfaction            94.8 100 120  cx777777 cxbbbbbb cxdddddd   4.50 30 25 20 25 20 15 30 70 90 20 20 30
Flight Utilization              100.0  80 100  cx777777 cxbbbbbb cxdddddd  90.00 15 10 30 60 90 75 75 45 15 10 45 20
Ratios                          .     .   .    cxffffff cxffffff cxffffff    .  . . . . . . . . . . . .
Profit / Passenger              110.0  80 100  cx777777 cxbbbbbb cxdddddd   0.20 20 92 70 50 75 70 50 92 40 60 40 20
Revenue / Passenger             111.5  80 100  cx777777 cxbbbbbb cxdddddd   0.60 90 90 92 92 90 85 85 30 85 90 90 90
Profit / Mile                   100.5  80 100  cx777777 cxbbbbbb cxdddddd  15.10 20 92 85 70 85 80 75 92 80 85 75 65
Revenue / Mile                  101.0  80 100  cx777777 cxbbbbbb cxdddddd  50.50 85 85 90 90 85 85 85 50 85 85 80 92
Fuel Costs / Mile               126.7 100 150  cxdddddd cxbbbbbb cx777777   3.90 75 75 85 92 15 20 20 20 35 20 35 50
;
run;

data mydata; set mydata;
if bar<mid1 then in_color=color1;
else if bar <mid2 then in_color=color2;
else in_color=color3;
run;

/*
To sort the data in the y-axis by the data-order, I assign a numeric variable,
and then later use a user-defined format to have the number print as the text name.
*/
data mydata; set mydata;
data_order+1;
run;

proc sql;
select count(*)-1 into :lines from mydata;
quit; run;
data mydata; set mydata;
y_line=&lines-data_order+1;
run;



data ignore_error;
function='seterror'; size=1000; output;
function=''; size=.; output;
run;

data anno_table; set mydata;
length function $8 color $8 style $20 text $50 html $100;
when='a';

/* Label in left column of each line */
xsys='1'; ysys='1';
function='label';
x=0;
y=(100/&lines)*y_line+((100/&lines)/2);
position='4';
text=trim(left(measure));
/* You could have a separate drilldown for each measure, etc */
html='href='||quote(trim(left('iPhone_dashboard_info.htm')));
if bar ne . then color="&dark";
else color="&darker";
output;

/* Red 'alert' dot, if you're in worst category */
if upcase(in_color)=upcase("&badcolor") then do;
x=3;
position='5';
size=.6;
style='"webdings"';
text='6e'x;
color='red';
output;
end;
style='';
size=.;

/* Bar value column, just to the left of the bullet graph */
color="&dark";
xsys='2'; x=-.06; position='4';
if bar ne . then text=put(bar*100,comma7.1);
else text='';
output;

/* CV value column, to the left of bar value column */
color="&dark";
xsys='1'; x=54; position='4';
if cv ne . then text=put(cv,comma7.2);
else text='';
output;

/* Annotated sparkline */
if line1 ne . then do;
xsys='1'; ysys='1';
function='move';
x=7; y=((100/&lines))*y_line + (100/&lines)*(line1/100); output;
function='draw';
x=x+3; y=((100/&lines))*y_line + (100/&lines)*(line2/100); output;
x=x+3; y=((100/&lines))*y_line + (100/&lines)*(line3/100); output;
x=x+3; y=((100/&lines))*y_line + (100/&lines)*(line4/100); output;
x=x+3; y=((100/&lines))*y_line + (100/&lines)*(line5/100); output;
x=x+3; y=((100/&lines))*y_line + (100/&lines)*(line6/100); output;
x=x+3; y=((100/&lines))*y_line + (100/&lines)*(line7/100); output;
x=x+3; y=((100/&lines))*y_line + (100/&lines)*(line8/100); output;
x=x+3; y=((100/&lines))*y_line + (100/&lines)*(line9/100); output;
x=x+3; y=((100/&lines))*y_line + (100/&lines)*(line10/100); output;
x=x+3; y=((100/&lines))*y_line + (100/&lines)*(line11/100); output;
x=x+3; y=((100/&lines))*y_line + (100/&lines)*(line12/100); output;
end;


/* create the 1st shaded areas behind the bullet graph */
ysys='1';
xsys='2';
function='move';
x=0;
y=(100/&lines)*y_line + (100/&lines)/5;
output;
function='bar'; line=1; size=2;
x=mid1; color=color1; style="solid"; line=0;
y=((100/&lines))*y_line + (100/&lines) - (100/&lines)/5;
output;

/* create the 2nd shaded areas behind the bullet graph */
xsys='2';
function='move';
x=mid1;
y=(100/&lines)*y_line + (100/&lines)/5;
output;
function='bar'; line=1; size=2;
x=mid2; color=color2; style="solid"; line=0;
y=((100/&lines))*y_line + (100/&lines) - (100/&lines)/5;
output;

/* create the 3rd shaded areas behind the bullet graph */
xsys='2';
function='move';
x=mid2;
y=(100/&lines)*y_line + (100/&lines)/5;
output;
function='bar'; line=1; size=2;
x=2.0; color=color3; style="solid"; line=0;
y=((100/&lines))*y_line + (100/&lines) - (100/&lines)/5;
output;


/* dark black bullet/bar representing data */
xsys='2';
function='move';
x=0;
y=(100/&lines)*y_line+((100/&lines)/2);
output;
function='draw'; color="black"; line=1;
size=8; /* this is the width of the black line (which is the 'bar' in the bullet graph) */
x=bar;
output;

/* Line between (below) each label */
function='move';
xsys='3'; x=0;
ysys='1';
y=(100/&lines)*y_line;
output;
function='draw'; line=1; size=1;
if bar=. then color='gray99';
else color='grayee';
x=100;
output;

run;


data anno_table; set ignore_error anno_table;
run;





data anno_other;
length function $8 style $20 text $80;


/* line above table */
when='a';
xsys='3'; ysys='1';
function='move'; x=0; y=100; output;
function='draw'; x=100; y=100; color="&dark"; when='a'; line=1; output;

/* dark line on 0-200% axis */
xsys='2'; ysys='1';
function='move'; x=0; y=0; output;
function='draw'; x=2; y=0; color="&dark"; when='a'; line=1; output;

/* labels at top of table */
function='label'; size=.; style=''; color="&darker";
ysys='1'; y=102;
xsys='2'; x=0; position='6'; text='% Target YTD'; output;
xsys='1';
x=0; position='4'; text='Key Figures'; output;
x=24; position='5'; text="11/04 - 10/05"; output;
x=53; position='4'; text="CV"; output;
color='';

run;

data anno_other; set ignore_error anno_other;
run;



/* Modify a style, so it has a black/dark background in the webpage */
ods path work.template(update) sashelp.tmplmst;
proc template;
define style styles.iphone;
   parent = styles.default;
   replace colors / "docbg" = cx111111;
   replace Output from Container / bordercolor = cxbbbbbb;

end;




GOPTIONS DEVICE=png;

/* This is the size of the iPhone Screen */
*goptions xpixels=320 ypixels=480;

/* But the mobile-Safari browser doesn't show web pages at that resolution,
   so let's make it twice as big.  Also, it's better to create the png file
   as 'bigger' than you want it, so the resolution looks good when you
   'Zoom' in with your fingers. */
*goptions xpixels=640 ypixels=960;

/* But, since you're going to display in the mobile-Safari browser,
   you need the size to be larger in the x-direction (since the browser is
   consuming space at the top/bottom in the Y direction */
goptions xpixels=750 ypixels=960;

goptions border;
ODS LISTING CLOSE;
ODS HTML path=odsout body="&name..htm" (title="SAS/Graph iPhone Dashboard") style=iphone;

/*
goptions ftitle="arial/bold" ftext="arial" gunit=pct htitle=10pt htext=7pt;
*/
goptions ftitle="albany amt/bold" ftext="albany amt" gunit=pct htitle=4 htext=2;
goptions ctext=&dark;
goptions cback=white;

axis1 label=none style=0 value=none major=none minor=none offset=(0,0);

axis2 label=none style=0 order=(0 to 2 by 1) minor=none offset=(45,0) value=(t=1 j=c t=2 j=c t=3 j=l);

symbol1 v=none c=white h=.001;

title1 ls=1.2 color=&medium "SAS/Graph iPhone Dashboard";
title2 h=5pct " ";
title3 a=90 h=18pct " ";

proc gplot data=mydata anno=anno_table;
plot data_order*bar / vreverse
vaxis=axis1
haxis=axis2
anno=anno_other
noframe
des="" name="&name";
run;

/*
proc print data=mydata;
run;
proc print data=anno_table;
run;
*/

quit;
ODS HTML CLOSE;
ODS LISTING;


/*
You could now mail the dashboard to someone (ie, mail it to their iPhone)
using code like the following...
(I have commented out the code, so it doesn't send me the dashboard every
time it's run though :)
*/

/*
%include 'iPhone_mailer.sas';
*/[/code:3seftokx]
[img:3seftokx]http://robslink.com/SAS/democd38/idashboard_sas.jpg[/img:3seftokx]
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
沙发
 楼主| 发表于 2012-8-21 16:46:04 | 只看该作者

Re: SAS/Graph iPhone Dashboard

喵了个咪的 这是iphone的福利么?
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|Archiver|SAS中文论坛  

GMT+8, 2025-5-3 09:21 , Processed in 0.081551 second(s), 20 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表