Using SAS to Create Graphs with Pop-up Functions

Document Sample
Using SAS to Create Graphs with Pop-up Functions Powered By Docstoc
					                                                   Paper CC12

            Using SAS® to Create Graphs with Pop-up Functions
                      Shiqun (Stan) Li, Minimax Information Services, NJ
                                 Wei Zhou, Lilly USA LLC, IN

In addition to the static graph features, SAS provides another strong capability to create dynamic graph displays
for information visualization. In this presentation, we will demonstrate a SAS component that can generate a
SAS graph with pop-up and drill-down functions. In a pop-up graph, when the mouse is moved over different
regions or points of such a graph, additional information will appear in a pop-up box. A drill-down graph is often
used to link different graph area with different new graphs or tables. This type of SAS graph outputs are quite
suitable for a web-based presentation. The topic is prepared for an intermediate and advanced audience.

Key Words: SAS/graph, information visualization, pop-up, drill-down, html, Javameta, web-based analysis

There are many papers discussing about SAS graphs. Most articles present techniques on creating static SAS
graphs. However in many situations, we are interested not only in displaying the data in a graph, but also in
showing the further information associated with the points, lines or areas in the graph. For instance, in a
regression plot, we may want to move the mouse over to an outlier and find out more detail information about
this outlier point.

Pop-up and drill-down are nice features for data exploration. To create a dynamic SAS graph for a web
browser, there are three things needed to be set up:
    1. Specify what to pop-up and/or where to be linked to;
    2. Associate the pop-up tips with the graph areas
    3. Use SAS HTML option and graph device drivers for displaying the graph in a browser.

1. Define a pop-up and drill-down

1) Pop-up
The contents in a pop-up window can be defined in a data step using data tips. It is just like create a text string
beginning with a tag key word TIP or ALT. The format of this string is:
TIP=[“the contents to be displayed”]
ALT=”the contents to be displayed”

A simple statement for specifying a pop-up string is like:

popup=compbl('TIP=[' || quote("PID: " || put(PatID,$28.)) ||']');
tips=compbl('ALT=' || quote( 'PID:' || put(PatID, $28.)) );

In the example above, the text string <PID: xxxxx> will show up in the pop-up window when the cursor is moved
to the corresponding graph region/point.

2) Drill-down
A drill-down has two basic parts: the pop-up contents and the links. It can be defined in the similar way to that of
a pop-up. In addition to the pop-up information, a href tag is used to link to another source. The format of a drill
down string looks like:
ALT=”Click Here” href=”level2.html”

Here, the href tag can be an internet address, like:
PopLink =compbl('TIP="Click for more detail" href='||quote(“”));

Or it can be a file located in your computer:
PopLink =compbl( 'TIP="Click for more detail" href=' ||

The file to be linked to can be a html file, a pdf file, a Word document or a picture like a jpg or gif file.

A pop-up and drill-down can also be defined in an annotate data set. This gives us many flexibilities in
programming. In an annotate data set, we need to create a variable HTML as following:

Length html $50;
Html='Alt="SAS Company" href="" ';
%label(x, y, "SAS", Blue,0,0,2,simplex,2);

This will generate the word <SAS> in (x, y) position. When the cursor is moved over the word <SAS>, a pop-up
<SAS Company> will be displayed and it will direct to SAS web: if we click at it.

2. Associate the pop-ups with the graph areas
After the data tips are defined in the dataset, the pop-ups can be associated with the SAS graph simply by
adding html=popup in the graph options, like this:

plot (pred L95m u95m)* weeks /overlay html=popup;

If variable HTML is created in an annotate data set, ANNOTATE option should be used in SAS/Graph

3. Displaying the graph in a web browser
Pop-up and drill-down usually require a graph device driver like ACTIVEX, JAVA, or JAVAMETA and ODS
HTML. There are several papers [1,2,3] that discuss about this in details.

Below is an example to save a dynamic SAS graph to a HTML file. This applet graph can then be opened in a
web browser.

goptions reset=all device=javameta
ftext='HelveticaBold' htext=5 gunit=pct colors=(black);

ods listing close;
ods html file='C:\Examples\PopUp\Popup_Example.html'
attributes=(codebase="C:\Program Files\SAS\shared\applets"

The CODEBASE=”C:\Program Files\SAS\shared\applets” specifies a local directory. To enable the pop-up
functions, the html file pop-up_example.html can only be displayed in a computer with SAS installed in the same
directory. However, after a file is produced, it is often going to be passed from hand to hand. SAS system may
be installed in a different directory for a different computer, or there may not have SAS system in the machines
used for presentation. To avoid this problem, CODEBASE parameter can be changed to a location that can be
reached from internet. For test purpose, we choose:
This APPLET is stored on the web space managed by Mike Zdeb of SUNY at Albany[1].

If a computer cannot access to the internet and does not have SAS system installed, you could still use it to
display a SAS output with pop-up properties. You should copy the whole applets directory (C:\Program
Files\SAS\shared\applets), as well as the html file Popup_Example.html, to that computer.

Here we will present a real world case of using a dynamic SAS graph. In this example, we have data from a
study with 4 arms of treatments (Placebo, Treat A, Treat B and Treat C). We are interested in the relationship
between the reduction of primary respond and some baseline variables. Therefore, we create the scatter plots
with the regression line as well as the 95% confidence lines.

 In this graph, when we move the mouse to points on the scatter plots, additional patient information (like patient
ID, age, BMI etc) will be displayed. If we move the mouse to the regression line, it will show the fitted model.
This move-over or pop-up function can only display in HTML web-based format. If you want to move a SAS
output with pop-up/drill-down properties to Powerpoint slides, you will need to do some ‘Add-ins” in your
Powerpoint software. To learn how to insert a web page with JAVE applets etc to a Powerpoint presentation,
please refer to this “LiveWeb”[6] for detailed instructions.

A screen from the web is showed below. The SAS code that generates the graph is attached in the appendix.
The SAS program was run in SAS version 8.

In this plot, there are two features: 1) If we move the cursor to the point of a patient, as we can see from the
pop-up window, the patient ID, treatment arm and some other additional patient information will be popped-up.
2) If we point to the regression line, the regression model will be displayed. And if we click at this line, it will
bring us to a new web page showing us the details of the model.

This plot only shows the result of Treat A. Quite often, projects require to show all the 4 treatment arms in one
single page, in a 2 by 2 template. Our first try was to use GREPLAY. Unfortunately, GREPLAY did not work for
us. It loses the all the pop-up and drill-down functions. We also tried ODS LAYOUT on SAS version 9. It seems
ODS LAYOUT will lose the pop-up and drill-down capability too.

Fortunately, it is very easy to re-arrange the layout of the html graphs, with a little help of some HTML skills. We
first generate all the 4 graphs in one html file, then modify this html file with the following SAS code. This will
rearrange the 4 graphs into a 2X2 graphs on a single page.

data _null_;
infile 'C:\Examples\PopUp\Treat4x1.html';
file 'C:\Examples\PopUp\Treat2x2.html';

IF upcase(_infile_)=:"<APPLET" then do;

  if count=1 then do;
    put '<p color=blue><font size="5"> Study XYZ: Change from Baseline <font
       '<br color=black><font size="3">
   (Mouse over to the points for patient information or click at regression line
for model outputs)<font size="3">' / '<br>'/;
    put "<table><tr><td>" /   "<!--- define a 2 by 2 table --->"//;
  if count=2 or count=4 then put "</td><td>" //;
  if count=3 then put "</td></tr><tr><td>"//;

IF _infile_=:'<p style="page-break-after:' then delete;
put _infile_;

IF upcase(_infile_)=:"</APPLET" and count=4 then do;
  put "</td></tr></table>" /   "<!--- End of table -->"//;

The 2X2 graph display is shown below. This applet graph will preserve all the pop-up and drill-down functions.

Dynamic SAS graphs are excellent techniques for data visualization and data exploration, especially for web-
based presentations. With a little HTML knowledge, it is possible to create a information-rich, visual-pleasing
SAS graph.

1. Mike Zdeb, Pop-Ups, Drill-Downs, and Animation, SUGI 29

2. Curtis Smith, Creating Drill-Down Graphs Using SAS/Graph® and the Output Delivery System, SUGI 28,

3. Himesh Patel, Using SAS/GRAPH® Software to Create Graphs on the Web,

4. A. Darrell Massengill, Tips and Tricks: Using SAS/GRAPH Effectively, SUGI 30,

5. Shi-Tao Yeh, Interactive Graphs from the SAS® System, NESUG 18,

6. LiveWeb – insert and view web pages real-time,

SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS
Institute Inc. in USA and other countries. ® indicates USA registration. Other brand and product names are
trademarks of their respective companies.

Your comments and questions are valued and encouraged. Contact the authors at:

Shiqun (Stan) Li
Minimax Information Services
49 Hendrickson Dr.
Belle Mead, NJ 08502
(908) 240-8229

Wei Zhou
Drop Code: 4133
Indianapolis, IN
(317) 651-0044

SAS sample codes generate the dynamic graph:

*** 1) To create a mock-up data set;
data example;
length treat $10 gender $8 ;
  do patid=1 to 200;

        if patid<=50 then treat="Placebo";
        else if patid<=100 then treat="Treat A";
        else if patid<=150 then treat="Treat B";
        else if patid<=200 then treat="Treat C";

        if ranuni(0)<.51 then gender="Female"; else gender="Male";
        age=18+ranuni(0)*(80-18); *** 18 to 80 years old;


*** 2)To find the regression model and set up the pop-ups, drill-downs;
***   Preparing for the html graphs;
%macro byTreat(treat=, trt=);
data test;
set example;
where treat="&Treat."; *** subsetting;

*** get the range for x-axis;
proc sql noprint;
select min(baseline), max(baseline) into :min_bl, :max_bl
from test;
%let step=%SYSEVALF((&max_bl. - &min_bl.)/100);

*** get the model estimates;
*** save the model details for 2nd level drill-down;
ods listing close;
ods output "Parameter Estimates"=model(keep=variable estimate);
ods html path="C:\Examples\PopUp\Pt_Info" body="Reg_Model&Trt..html";
title "Regression Model (&Treat.)";
proc reg data=test ;
  model change=baseline;
ods output close;
ods html close;
ods listing;

proc transpose data=model out=model1(drop=_:);
id variable;

*** create a base for graph;
data base;
do baseline=&min_bl. to max(10, &max_bl.) by &step.;

data _null_;
set model1(rename=(baseline=coeff_bl));
*** model;
if coeff_bl<0 then s1=""; else s1="+";
call symput("model", compbl("Change="||put(intercept,8.3)||put(s1, $1.)||
put(coeff_bl,8.3)||"*(Baseline)") );
%put &model.;
data testB;
set test(in=inDat) base(in=inBase);
if InDat then base=0;
if InBase then base=1;
proc sort data=testB; by baseline;

proc reg data=testB noprint;
model change=baseline/clm;

OUTPUT OUT=pred_dat
data toPlot&Trt. ;
set pred_dat;
length popup $200;
if base=0 then do; *** individual patient information for pop-ups;
  popup=compbl('tip=[' || quote("PID: " || put(patid, 8.) ||","|| "Treat: " ||
  quote(" ")||
  quote("Baseline Information: ") ||
  quote("Age:" || put(age,3.) || ', ' || put(gender,$8.)) ||
  quote('Baseline X: ' || put(baseline, 4.1) || ', BMI: ' || put(BMI, 5.1)) ||']'
if base=1 then do; *** model pop-up and drill down to model details;
   pred =pred_; popup='tip=["Regression Model:"' || quote("&Model.")|| ']'
     output; pred=.;
   l95m=l95m_; popup=compbl('tip=["Lower Bound of the 95% Confidence Interval"]');
output; l95m=.;
   u95m=u95m_; popup=compbl('tip=["Upper Bound of the 95% Confidence Interval"]');
keep change pred L95m u95m baseline popup ;

%mend byTreat;

%byTreat(treat=%Str(Treat A), Trt=A);

*** set graphics options (specify the JAVAMETA device driver);
goptions reset=all device=javameta
ftext='HelveticaBold' htext=5 gunit=pct colors=(black);

ods listing close;
ods html path='C:\Examples\PopUp\' body='TreatA.html'
  Width="700" Height="500");

axis1 label=none ;
axis2 label=none order=(-20 to 20 by 5) ;
symbol1 h=2 v=dot c=black i=none l=1;
symbol2 h=1 f=simplex v='.' c=blue i=j l=1;
symbol3 h=1 f=simplex v='.' c=green i=j l=2;
symbol4 h=1 f=simplex v='.' c=red i=j l=2;
title h=6 "Treat A";
proc gplot data=toPlotA;
plot (change pred L95m u95m) * baseline /vaxis=axis2 haxis=axis1
       overlay html=popup ;

ods html close;
ods listing;


Shared By: