Title: Creating Dynamic HTML pages with PC SAS
1Creating Dynamic HTML pages with PC SAS
- as a prelude to SAS IntrNet or Integration
Technologies
Qiang Hou Harvard Pilgrim Health Care, Wellesley
MA qiang_hou_at_hphc.org
2Introduction
- This presentation will
- Introduce a simple technique to create dynamic
SAS-based web applications, employing PC SAS
and open-source software, as an alternative to
the SAS IntrNet and Integration Technologies - Use a Hello world-like example to demonstrate
the technique, with complete sample code
Note In the following slides SAS,
SAS/IntrNet, SAS/IT, SAS/BI are registered
trademarks of SAS Institute Inc.
3Steps
- Why web report
- Why dynamic web report
- What can/cannot be achieved using PC SAS for web
reporting - A hello world example
- Toolkit set up
- Sample code
41. Why web reports?
- Compared to a traditional paper report, a web
report is - more environmentally friendly
- easier to update, even without reader awareness
- easier to deliver
- easier to automate
- quick for cross references and drill-down
51. Why web report? continued
- A screen-shot of a real web report with 5000
pages and mouse hover-over, drill-down
capability. It was created by PC SAS.
62. Why dynamic web report?
- Static web report
- Advantages
- Displays quickly
- Report creator has chance to proofread every
page - Limits
- The possible user selections have to be finite
- The underlying data has to be relatively stable
- Dynamic web report
- Advantages
- Allows continuous parameters in user requests
- Report based on real-time data
- Limits
- Longer waiting time for user to see the report if
huge amounts of data or super complex analysis is
involved - Some software and development overhead
73. What PC SAS can/cannot do for web report
- PC SAS is strong enough to build static web
applications - Handy to build reports in multiple formats
html, pdf, rtf, etc - Minimum requirement on programming skills
- Rich of features
- Hover-over mouse tip text
- Clickable graph area (drill-down)
- 3-D graphs with Java and ActiveX
- Build-in functions for frame and content page
creating. - CCS style sheet support
- More
- PC SAS is not designed to serve remote requests
- SASs solutions to make the html report dynamic
- SAS/IntrNet ()
- SAS/IT ()
- SAS/BI (?)
If you dont have these products but still
want to make your web report real-time dynamic or
do a prototype stage design, the technique we are
introducing may help.
84. A hello world example
We use a simple concrete example to illustrate
the technique
1. A remote or local user launches a web browser
and inputs two parameters --- a stock ticker and
a date
2. The stocks daily closing price history is
displayed
95. Toolkit set up
- The toolkit contains three components
- PC SAS
- Apache (open source web server, 0)
- PhP (a messenger between PC SAS and Web server,
0)
Apache
User request
SAS
PhP
Generated report
- User submits input
- PhP receives the request and then
- processes the input and generates a SAS calling
program - lunches SAS with the calling program
- 3. SAS calling program calls stored macro
functions to produce report - 4. PhP displays the report back to users
browser
105. Toolkit set up continued
- Install Apache and PhP
- Prepare three folders
- C\WebApps\Svr (for Apache/PhP installation tree)
- C\WebApps\SasPrg (for stored SAS programs and
data) - C\WebApps\Temp (for temporary SAS programs and
output) - Download and install the IndigoAMPP package from
http//www.indigostar.com/indigoampp.html - Note IndigoAMPP is a distribution of Apache,
MySQL, PHP and Perl for Windows. IndigoAMPP is
easy to install and to use - just download, and
run the installer. Apache will be configured to
work with MySQL, Perl and PHP. IndigoAMPP is free - Reboot and start Apache from Start-gtPrograms-gtIndi
goAMPP
116. Sample code
Apache
Index.html
PhP
PhP
plotStock.sas
User request
stock_test.php
SAS
Generated report
- 6.A Stored SAS program (C\WebApps\SasPrg\plotStoc
k.sas ) - 6.B PhP script (C\WebApps\Svr \stock_test.php)
- 6.C User input form (C\WebApps\Svr\index.html)
126.A Prepare SAS program plotStock.sas
- Prepare stored SAS program
- Write main SAS programs in macro functions. These
macro functions will be called with simple input
arguments to generate expected html pages - In our example the file plotStock.sas contains a
function plotStock(). It can be called by a
simple calling program - include "C\webApps\SasPrg\plotStock.sas"
- plotStock(stockYHOO, start01/12/08 )
- Test the stored SAS program locally
- Save above two lines in getstock.sas and it from
command-line - C\Program Files\SAS\SAS 9.1\sas.exe
-log saslog.txt -print sasout.txt - -sysin C\WebApps\Temp\getstock.sas
136.B Create PhP script interfacing Apache, SAS and
web browser
- PhP script stock_test.php will
- Accept the user request, and create a short SAS
calling program getstock.sas that ends with a
call to a SAS macro, with parameter values based
on the users inputs - Launch SAS in batch mode from command-line to run
the stub program and create html pages - Return the result (URL) to user
- The sample code (25 short lines) appears as the
second page in the appendix
146.C Create user input form (index.html)
- A simple HTML form
- With user input/selection fields
- Specifies the PhP script being used to process
the user request - A submit button
- The sample code (15 short lines) appears as the
first page in the appendix
156.D Watch it in action
- Launch browser from http//svrHostname/index.html
- Input a stock ticker and a start date
- Wait to see the plotted daily closing price
16Notes
- To simplify the demonstration we have skipped
- Concurrent user session management
- Disk space cleanup
- Security issue handling
- Although we have tested the setup and program
code presented here, this technique is new and is
not present in SAS publications. Therefore, you
should proceed with caution. The author is not
responsible for any damage that may result from
using the technique presented here - Once the dynamic web application has been
designed, tested, and approved, SAS IntrNet and
Integration Technologies can then be evaluated
for development of a production application
17Acknowledgement
- I would like to acknowledge my colleagues and
BASUG community for their supports, especially
thank Bob Virgile for his suggestions and
comments. - SAS and all other SAS Institute Inc. product
or service names are registered trademarks or
trademarks of SAS Institute Inc. in the USA and
other countries.
18Appendix Index.html
- lthtmlgtltbodygt
- lth4gtType in a stock symbol and start date lt/h4gt
- lthrgt
- ltform action"Stock_test.php" method"post"gt
- lttablegt
- lttrgt
- lttdgtStock symbol lt/tdgt
- lttdgtltinput name"Symbol" type"text" /gt lt/tdgt
- lt/trgt
- lttrgt lttdgtStart date (mm/dd/yy)lt/tdgt
- lttdgtltinput name"Start" type"text" /gt lt/tdgt
- lt/trgt
- lttrgt lttdgt lt/tdgt
- lttdgt ltinput type"submit" /gt lt/tdgt
- lt/trgt
- lt/tablegt
- lt/formgt
- lt/bodygtlt/htmlgt
19Appendix stock_test.php
- lt?php
- stock _POST'Symbol'
- start _POST'Start'
- call "". "price(stock " . stock . ",
start " . start . " )\n" - f fopen("C/WebApps/Temp/getstock.sas", "w")
- setParas""."include \"C\\WebApps\\SasPrg\\pl
otStock.sas"\n" - fwrite(f, setParas)
- fwrite(f, call)
- fclose(f)
- cmd "\"C\\Program Files\\SAS\\SAS
9.1\\sas.exe\" -log saslog.txt -print sasout.txt
sysin C\\WebApps\\Temp\\getstock.sas" - handle popen(cmd, "r")
- ret ""
- do
- data fread(handle, 8192)
- if(strlen(data) 0) break
- ret data
- while(true)
- pclose(handle)
- header("Locationhttp//SrvHostName/Temp/test.ht
ml")
20Appendix plotStock.sas
- /
- Draw stock daily closing price
- /
- MACRO drawDailyPrice(inDS, htmlDir, fn,
stock) -
- goptions resetglobal noborder
gsfmodereplace devicegif transparency - display ftitle"arial" ftext"arial"
htitle5pct htext3pct - ods html path"htmlDir" gpath"htmlDir/gif"
(url"gif/") - body"fn..html" styleminimal
- symbol1 interpoljoin valuedot height0.4 cred
line1 w1.5 - axis1 label(h1.5 "Date") Colorgray WIDTH1
- axis2 Colorgray label(a90 "Closing price")
minornone width1 - proc gplot data inDS
- plot closedate/ Vaxisaxis2 haxisaxis1
nolegend noframe - title h1.8 jr "stock historical closing
price" - title2 h1 jr "created on sysdate at
systime" - run
- quit
- ods show
- /
- Query stock closing price from Yahoo web site
and plot it - /
- MACRO plotStock(stockYHOO, start, end)
- LET smSYSEVALF(qscan(start, 1, '/')-1)
- LET sdqscan(start, 2, '/')
- LET syqscan(start, 3, '/')
- let and str()
- let url http//ichart.finance.yahoo.com/tab
le.csv?sstock - let url url.and.asm.and.bsd.and.c
sy - let url url.and.gdand.ignore.csv
- filename yahoo URL "url"
- data t
- infile yahoo dlm','
- retain symbol "stock"
- if _N_ 1 then input
- input date yymmdd10. open high low close
volume adjClose - format date mmddyy8. close dollar.
- run