DP Using Sas Mysql and

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

Using SAS, MySQL, and PHP to Empower 1

Using SAS, MySQL, and PHP to Empower End-Users to Generate


Dynamic Descriptive and Analytic Statistical Web Reports

Jeremy Morris, Gary Levy & Ray Dahl


University of Utah, Office of Budget & Institutional Analysis (OBIA)

Abstract and analytic activities, but this has not


been the case.
Organizations typically post static and
finished reports in HTML or PDF form to Unfortunately and partly as a result of
web pages. However, administrators and large investments of resources in costly
decision-makers are increasingly enterprise systems (e.g.,
demanding more dynamic, end-user PeopleSoft/Oracle, Banner) as well as
driven web applications for creating their the inherently poor reporting applications
own unique data queries and associated with such enterprise systems,
professional descriptive reports. In many higher education institutional
addition to simple descriptive reports research offices have instead stuck with
such as those providing means or static web pages containing HTML and
frequencies integrated use of SAS Stat PDF report formats.
software affords generation of analytic
statistical reports and analyses. In contrast, our OBIA office has been
aggressively developing web-database
This paper introduces and details the applications using what is commonly
SAS programming and hardware, as well referred to as a LAMP (Linux-Apache-
as other non-SAS software (e.g., PHP) MySQL-PHP) architecture.
used to create a dynamic, end-user
driven web application that produces Our OBIA office also uses SAS for data
reports containing any SAS output. manipulation, report generator, and
statistical analysis. The potential of
integrating the reporting and analytic
1. Introduction powers of SAS with the strengths of the
LAMP environment was very appealing.
Although many for-profit and
entrepreneurial businesses have
developed and embraced advanced 2. Descriptive & Analytic Reports
reporting and data warehousing
applications, higher education settings Administrative and academic decision-
have been slow to follow. makers frequently inquire about a similar
set of general metrics or indices in
One would think that certain units in assessing their operations. Examples of
higher education, such as financial such indices include student credit hours,
services and institutional research class enrollments, numbers of majors,
offices, would have incorporated such student responses to surveys, etc.
technologies in their day to day reporting
Using SAS, MySQL, and PHP to Empower 2

Descriptive reports are those that


present descriptive statistics. We can The first stage is Input Collection.
define descriptive statistics as statistical During Input Collection, the end-user
techniques used to easily summarize a follows a few steps and chooses a
set of data. survey, a question from that survey and
an alternate variable to break down the
Typical descriptive statistics include resulting statistics. This first stage of the
tabular summaries of data and simply solution is designed only using the LAMP
graphs and figures. Descriptive reports architecture, as seen below.
typically present summary information
such as measures of central tendency
(means, median, and mode), measures
of data dispersion and distribution such
as standard deviations, range, variance,
and skew.

Analytic reports draw on analytic or


inferential statistics. We can define these
statistics as statistical techniques used to
draw inferences about a sample or
population (rather than merely describe
them). Additionally, inferential statistics After the end-user has chosen the inputs
allow hypothesis testing, significance they are sent to SAS/IntrNet for the
testing, correlative models, and second stage, termed Result
sometimes even tests of cause and Calculation and Display. This stage is
effect, something that descriptive performed completely by SAS through
statistics are not capable of. the Application Dispatcher. Using HTML
forms, we send the collected inputs from
3. The Project at Hand Stage One to a SAS system. This is
illustrated in the following figure.
We had an initial project in mind when
we embarked on using a PHP-MySQL-
SAS system for reporting purposes. Our
goal was to develop a simple web
application that would permit end-users
to generate simple descriptive statistics
for student survey data collected by our
OBIA office over a series of years. For
example, end-users might be interested
in what percentage of undergraduate
transfer students report being married, or
perhaps how satisfied graduating seniors
were with courses in their major.
A benefit of this system design is that we
3.1 Web Architecture are able to exploit the strengths of each
The web application created to address technology and avoid using other
our project goals operates in two stages.
Using SAS, MySQL, and PHP to Empower 3

solutions that do not include the specific The aim for stage one was to design a
features that we need. simple interface for end-users to interact
with. Apache, MySQL and PHP are
For example, PHP was designed widely available and widely used for this
specifically to create dynamic database purpose. All three are open source
driven web applications such as the one projects, meaning that there are no direct
used in Stage One, and SAS has fiscal costs for the licensing or use of the
advanced capabilities to deliver reports software.
and statistical analysis. By using our
setup we are able to avoid building All three software products can be found
custom reports in PHP or designing a on the Internet and include full
web application with SAS, either of which instructions for installation. We
would be an enormous headache. recommend reading all documentation
and installation instructions carefully
3.2 Survey Data Tables in MySQL before attempting to install or setup any
of these software packages. Any
problems encountered can usually be
We needed to redesign our database to solved by using your favorite search
complete this project. We started with a engine (e.g., Google).
table representing the result set from
each survey administered. Each table Apache is a web server and is the silent
followed a slightly different format with partner in the entire operation. Apache’s
differing field names and Dynamic Web- primary job is to monitor all web activity
based Reports Using SAS 3 types. and send requests back and forth
through the Internet.
We decided to alter the structure of each
table creating two fields (a numeric field
and a character field) for each field that 4.1 HTML Forms
previously existed to take advantage of The fundamental idea of the Input
the full capabilities of SAS. Collection stage is to allow the end-user
to choose options from a website and
We also decided on a naming convention then send those inputs to SAS. We
to standardize all tables. Then we needed to use HTML forms to do this.
developed two tables for use in the Input
Collection phase. The first table is a The form object is a collection of HTML
simple list of surveys that the end-user is elements that allow the end-user to
allowed to choose from together with submit or input information which can
some other data about each survey. then be processed by client or server
The second table warehouses the text for based applications. Below are examples
each survey question asked along with of form definitions.
an identifier that corresponds to the field
<form name="AName" method="GET"
names from each survey table. This action="web address">
allows us to only display question text insert sub-elements here
and to tell SAS in what fields we are </form>
interested.
4. Input Collection (Stage 1) or
<form name="AName" method="POST"
action="web address">
Using SAS, MySQL, and PHP to Empower 4

insert sub-elements here Application Dispatcher that we will


</form> discuss in more detail.

PHP and SAS, in this instance, both <input type="hidden" name="_service"


qualify as server side applications. The value="name">
form object has a set of sub-elements <input type="hidden" name="_program"
that allow the end-user to change the value="name">
inputs. The inputs we used include select
boxes, radio buttons, submit (buttons), 4.2 PHP
and hidden inputs.
We are using PHP to query a MySQL
Select boxes (commonly known as drop database and fill in some of the form's
downs) allow an option to be chosen sub-elements, such as the select boxes
from a list. and radio buttons. There are a few
different versions of PHP and PHP
<select name="some name">
<option value="">some modules.
text</option>
</select> We use PHP5 with the PEAR package
enabled. PHP has an online manual with
Values in a form can be supplied and/or several tutorials on how to program using
altered by end-user or can be supplied by PHP and how to do simple things like
a server side application. In our case we connect to a database, perform a query
supply the values in select boxes and and display or use the results. This
radio buttons via PHP and MySQL. manual can be found at:

The submit button activates the form http://www.php.net/manual/


action. The names and values
associated with each of the defined form PHP is straightforward to learn and for
sub-elements, or inputs, are passed from this reason we leave it up to the reader to
the client to the program on the server find more on this topic.
defined by the HTML form action
attribute. This data is passed via the 4.3 MySQL
defined method attribute (GET or POST)
of the form tag. MySQL also has a strong presence on
<input type="submit" value="Submit"> the web. A comprehensive manual can
be found at:
Notice that there are two options for the
method attributes. GET sends the inputs http://dev.mysql.com/doc/mysql/
into the address string and POST sends
them through a special mechanism that This manual includes a tutorial that can
can only be used by a server side be used as a good start, and includes
language. Either method can be used everything needed to use and administer
when submitting inputs to the Application a MySQL database. It can also be found
Dispatcher. in print form at your favorite local,
There are also two hidden fields that privately owned, bookstore.
pertain to options required by the 5. Result Calculation and Display
(Stage 2)
Using SAS, MySQL, and PHP to Empower 5

The action attribute can be seen where


After the end-user has clicked the submit address refers to the web address of
button, all inputs are sent to SAS to a your SAS/IntrNet machine or the IP
SAS/IntrNet program called the address of this machine.
Application Broker. The main purpose of
the Application Dispatcher is to provide a action=http://address/cgi-
bin/broker.exe
CGI gateway between a Web browser
and SAS. Once the Dispatcher is set up
and the service is running, the end-user 5.1 Required Inputs for the
only needs worry about the design of the Application Dispatcher
SAS program.
When a request is sent to the Application
The Application Dispatcher requires a Dispatcher, it must include two inputs.
web server for its setup. The Application These inputs tell the broker.exe which
Dispatcher is defined as a Compute service to use and which SAS program to
Service. We are running Apache and run. We have implemented both as
SAS/IntrNet on a Windows machine. hidden inputs.
Compute Services give the 5.1.1 _service
end-user full access to the
analytical capabilities of the
The _service input must be set to the
SAS server. End-users can
name of the service you want called.
access and use any non-visual
Again, this is set up using the socket
functionality provided by the
service wizard. On
SAS server (from SAS IntrNet:
our system we start this service by
A Roadmap).
running the appstart.bat batch file that is
in the service directory.
Run the Create a New IntrNet Service
9.1 wizard to set up the Application
Dispatcher. When we did this on our 5.1.2 _program
Windows machine it created a folder in
C:\ Program Files\ SAS\IntrNet with the The _program input refers to the SAS
chosen service name. We will need to program that you want to run. The
alter some of the files in this folder for the program name must have three or four
service to work properly. levels delimited by periods to work
properly. If it does not, you will get an
At the time of this publication we have error message reminding you.
done this setup in the Windows
environment only. We have plans to try Lines must be added to the appstart.sas
this in a Linux environment. file in the service's directory to define the
library section of this identifier.
When the Application Dispatcher is location refers to the folder where all
configured, a CGI program called SAS programs will be located.
broker.exe is placed in the cgi-bin
directory of your web server. You must
allocate file library `location';
specify this program when defining the proglibs library;
action attribute of the form tag.
Using SAS, MySQL, and PHP to Empower 6

5.2 Extra Inputs (dynamic title="&mytitle") rs


= none
style = Brick;
The Application Dispatcher can accept
an arbitrary number of extra inputs. title "&name";
These can appear in your SAS program
as variables. For example, if we were proc tabulate
interested in allowing the end-user to data=work.my_survey;
specify the gender and marital status of a class &options &question;
specific type of student, we could define var dummyN;
table (&options=' ') all,
three inputs named gender, marital (&question=" ")*ROWPCTN
and studentType. dummyN=''*n;
keylabel n = '# Responses'
Then we would refer to these inputs as rowpctn = ' '
the variables &gender, &marital and all = 'Mean Response';
&studentType in the SAS program. run;

ods html close;


5.3 SAS Program ods listing;

Here is an example of a SAS program Next we close ods listing and open
that will run when called by the ods html. Here we send the body to
Application Dispatcher. Any SAS _webout which means the output will get
program that can be called on the sent to the end-user's browser. Use
command line can be executed by dynamic title="" to set the text in
broker.exe, as we mentioned earlier. the title bar. Output style can be altered
using the style command. SAS has
We begin by using a libname statement several predefined styles to use, a
to create a library to the database holding custom style can be created using proc
all of our survey data. Next, we create a template.
temporary table using proc sql into the
work library. You can also link to an external style
Notice that we use the variable &survey sheet to change the look of your output.
which is sent through GET/POST as The title statement adds a title on
specifying the data requested by the end- your output, as opposed to the title in the
user. title
bar of the end-user's browser. Then we
libname SURVEYS mysql use proc tabulate to display our
user='user' password='pswd' results.
database='dbname'
server='ip' port=3306;
run; Notice that we have two variables in use,
&options and &question. These refer
proc sql; to two questions chosen by the end-user.
create table work.my_survey as Both show up in this case because as
select * from SURVEYS.&survey; class variables they happen to have
run; character data in them.
ods listing close;
Since we want the character data to
ods html body=_webout show up in the results we have defined a
separate column in each of our data
Using SAS, MySQL, and PHP to Empower 7

tables called dummyN. This column is all descriptive report for the survey data that
1's and only serves the purpose of giving we warehouse.
us a numeric column to work with for the
var statement. It would be as simple to create a web
interface for analytic reports. In this case,
We close with ods html and re-open just replace proc tabulate with proc
ods listing at the end of the program. glm or any other analytic procedure that
At this point the SAS program is finished SAS provides.
and the results are displayed to the end-
user's browser window. Contact Information
6. Conclusions Jeremy Morris
University of Utah
This paper demonstrates and documents Office of Budget & Institutional Analysis
how we integrated the LAMP architecture 110 Park Building
with the power of SAS to create dynamic 201 S. Presidents Circle
end-user driven web application that Salt Lake City UT 84112
produces reports containing any SAS
output. jeremydmorris@gmail.co

Recall that we began this paper by


mentioning that one of our goals was to
create both analytic and descriptive
reports. This is an example of creating a

You might also like