SlideShare uma empresa Scribd logo
1 de 138
Baixar para ler offline
SAS Stored Processes and
Developing Web Applications
Phil Mason
Independent SAS Consultant
SAS University Edition includes the SAS 9.4 products Base SAS®,
SAS/STAT®, SAS/IML®, SAS/ACCESS® Interface to PC Files, and
SAS® Studio. Runs in a Virtual Machine on PC, Mac or Linux. And you
can download it for FREE!!!
Did you know?
http://www.sas.com/en_us/software/university-edition.html
Contents
▪ Creating a Simple Web App using Enterprise Guide
▪ Make a report
▪ Turn it into a Stored Process
▪ Use Stored Process Web App
▪ Make a better Web App
▪ Add some HTML
▪ Add Java Script
▪ Make use of JavaScript libraries
▪ Identify a good visualisation
▪ Integrate with SAS Stored Processes
Make Report
1 of 6
Make a report
▪ Use Enterprise Guide
▪ Build a query
Query Builder
Query builder
Now you have a query
Make Stored
Process
2 of 6
Make a Stored Process
Name it
View code
Pick Repository
Librefs
Prompts
Data Sources & Targets
Review
Edit Stored Process
Stored Process
▪ Composed of:
▪ A metadata component
▪ A code component
▪ Alternative way to create a Stored Process
▪ Create the code with an editor
▪ In Management Console create the metadata/code
Let’s take a quick look at Management Console
Create using Management Console
Name it
Execution settings
▪ Select server to run it on
▪ Specify we want to stream output and that we can
produce a package
▪ Keep code in metadata
Edit Source Code
Define parameters
Run it via Enterprise Guide
Edit a Stored Process with Management Console
▪ Find the one you want and double click it
Management
Console
Name & Location
Management
Console
Management
Console
Management
Console
Management
Console
Management
Console
Management
Console
Stored Process Web Application
▪ Comes with Integration Technologies
▪ Needs some configuring, including a Web Application
Server
▪ Allows running a stored process
▪ From a web browser
▪ From any other place where you can use a URL
▪ e.g. An application such as EXCEL, MS Word
▪ Parameters passed on URL appear as macro variables
to Stored Process
▪ This is a great feature!
Stored process web application
Get a menu down left
Run stored process from web app
Run stored process from browser
Run stored process from excel
Open one to run it
Results of run appear in EXCEL
Add a Graph to Stored Process
Result in web
browser
Add parameter
Add prompt for macro parameter added
Stored Process using parameter
via prompt
URL showing parameter passed
http://my.server/SASStoredProcess/do?

_program=/Shared Data/SASTesting/
Test3&product_line=Children
http://my.server/SASStoredProcess/do?

_program=%2FShared+Data%2FSASTesting%2F
Test3&product_line=Children
Encoded
Enhance with
HTML &
JavaScript
3 of 6
Make a better Web App
▪ Use some HTML
▪ Gives us some more control
▪ Use some JavaScript
▪ Great for adding more interactivity
▪ Allows programming to control User Interface
Simple HTML
<html> <body>
<h1>Pick a report to run</h1>
<a href="http://my.server/SASStoredProcess/do?
_program=%2FShared+Data%2FSASTesting%2FTest3
&product_line=Children"> Children</a><p>
<a href="http://my.server/SASStoredProcess/do?
_program=%2FShared+Data%2FSASTesting%2FTest3
&product_line=Clothes+%26+Shoes">Clothes & Shoes</a><p>
<a href="http://my.server/SASStoredProcess/do?
_program=%2FShared+Data%2FSASTesting%2FTest3
&product_line=Outdoors">Outdoors</a><p>
<a href="http://my.server/SASStoredProcess/do?_program=%2FShared+Data
%2FSASTesting%2FTest3
&product_line=Sports">Sports</a><p>
</body> </html>
HTML Menu
Report shown in browser
Using a form to run a Stored Process
▪ HTML form is great for making User Interfaces
▪ Form tag
▪ Make the first part of URL
▪ Input tag, using different type settings
▪ Text – fields for text
▪ Password – passwords where text is hidden
▪ Radio – radio buttons
▪ Checkbox – check boxes
▪ Submit – submit buttons to execute URL using parts of form
HTML using Form
What’s displayed
Writing directly from Stored Process to browser
▪ _webout
▪ Reserved fileref for writing from Stored Process to browser
▪ %stpbegin macro sends output from procs to _webout
▪ %stpend stops output going to _webout
▪ Can write from a datastep to _webout
▪ Best to turn automatic Stored Process macros off
New stored process to write HTML
Stored process produces this
Add iFrame to keep output on same page
Now menu & output on same page
Useful optional parameters for Stored Processes
▪ _odsdest – lets us choose an ODS destination for type of
output produced
▪ Switch between HTML, RTF, PDF, EXCEL, etc.
▪ _odsstyle – choose an ODS style
▪ _debug – can produce the SAS log, execution times, etc.
▪ _debug=log,time
▪ _debug=2179 … this is my favourite
Define a dropdown menu for type of output
Output type is added to menu
HTML Headers
▪ Set headers in HTML from stored process
▪ Indicates what browser should do
▪ RTF
▪ EXCEL
rc = stpsrv_header("Content-type", "application/msword") ;
rc = stpsrv_header('Content-disposition','attachment; filename=test.rtf');
rc = stpsrv_header("Content-type", "application/pdf") ;
rc = stpsrv_header('Content-disposition','attachment; filename=test.pdf');
RTF output
Define dropdown for ODS style
Here is what 2 ODS style selections produce
Add some checkboxes
After report we get the log
After log we get time
Parts of URL for stored process call
http://khv-sas-iis.cfsi.local/
SASStoredProcess/do?
_program=%2FShared+Data%2FSASTesting
%2FTest3

&product_line=Children
&_odsdest=html
&_odsstyle=meadow
&_debug=log
&_debug=time
Useful automatic macro variables
Use automatic macro variables
▪ Construct a URL using:
▪ &_srvname
▪ &_srvport
▪ &_url
What’s good about this technique
▪ Easily make SAS code run from a web browser
▪ Generate HTML, Excel, PDF or RTF easily.
▪ Easily add parameters making it much more flexible
▪ Build up a multiple page Web Application
What’s not so good
▪ Tables and graphs don’t look as good as they could
▪ Can improve their look with some more work within SAS
▪ Tables lack some functionality
▪ Cant sort columns
▪ Slow using lots of data
▪ Table headers are not fixed, so they will scroll away if tables are long
▪ Only some basic widgets available for building a UI
▪ Only basic use of mouse for selecting
Adding some JavaScript for interactivity
▪ onLoad – execute when page finishes loading
▪ onUnload – execute when page closes
▪ onKeyPress – execute when a key is pressed
▪ onKeyUp – execute when a key is released
▪ onMouseOver – execute when mouse is over something
▪ onMouseOut - … when mouse moves away
▪ onMouseDown … when left button is pressed
▪ onMouseUp … when left button is released
▪ onClick … when left button is clicked
▪ onDblClick … when left button is double clicked
JavaScript Demo
▪ Lets see some of those things…
▪ Note: not all browsers support all JavaScript (in
the same way)
▪ Try things out in all the browsers you might use
<html>
<head>
<script type='text/javascript'>
var popwin = null;
function open_popup() {
if (popwin == null)
popwin = window.open(
'http://www.google.com',
'',
'top=150, left=350, width=250,
height=50, status=0, toolbar=0, location=0,
menubar=0, directories=0, resizable=0,
scrollbars=0'
);
}
function close_popup() {
if (popwin != null) {
popwin.close();
popwin = null;
}
}
function checkKey() {
var key = String.fromCharCode(
window.event.keyCode);
if (key == 'X') {
alert(
"You pressed the X key"
);
}
}
</script>
Some added JavaScript for extra functionality
JavaScript providing more interactivity
</head>
<body onload='alert("finished loading");' onunload='alert("finished unloading");'
onkeypress='window.status="key pressed is: " +
String.fromCharCode(window.event.keyCode) ;'
onkeyup='window.status="key up"; checkKey() ;'>
Pop-up a window with information by moving over <a href='#'
onmouseover='open_popup(); window.status="Hovering over the link" ; return true ;'
onmouseout='close_popup(); window.status=" " ; return true ;'>here</a>.
<p>Pop-up a window with information by holding mouse button down <a href='#'
onmousedown='open_popup();' onmouseup='close_popup();'>here</a>.
<p><a href='#' ondblclick='open_popup();'>Double click to open</a>,
<a href='#' onclick='close_popup();'>single click to close here</a>.
<p><a href='#' style='font-size="x-large"' onmousemove='open_popup();'>Move
mouse over this to open</a>,
<a style='font-size="x-large"' href='#' onmousemove='close_popup();'>move
over this to close</a>.
<p>Press <b>X</b> to make an alert window pop up.
<p>Hold down a key to see what it is in the status bar.
</body>
</Html>
Stored Process generates HTML
Some excerpts…
<form method="get" action="http://khv-sas-iis2.cfsi.local/SASStoredProcess/do?" target="content">
<select name="_program">
<option value="/Shared Data/SASTesting/cabotCollectionsDashboard">Month to Date</option>
<option value="/Shared Data/SASTesting/ccDashDaily">Daily</option>
<option value="/Shared Data/SASTesting/ccDashYTD">Year to Date</option>
</select>
<input type="checkbox" name="_debug" value="log">Show log<nbsp><nbsp><nbsp>
<input type="checkbox" name="_debug" value="time">Show time taken<nbsp>
<input type="checkbox" name="inline" value="1">Inline?<nbsp>
<input type="submit" value="Run"><br>
More excerpts of HTML
organisationName <select name="organisationName" onchange="this.form.submit();">
<option value="Cabot Debt Purchase " selected>Cabot Debt Purchase </option>
<option value="Cabot Stratford Serviced ">Cabot Stratford Serviced </option>
</select>
</form>
<iframe name="content" height="85%" width="100%">
</iframe>
</body>
</html>
Use JavaScript
Libraries
4 of 6
A few good JavaScript libraries
▪ jQuery
▪ Write less, do more
▪ HandsOnTable or EasyUI
▪ Excel-like spreadsheet for Apps
▪ HighCharts
▪ Create interactive web charts easily
▪ D3
▪ Data Driven Documents
Manipulating your web page
▪ jQuery makes it easy to select parts of your page and
attach functionality
$(document).ready(function(){
$("button").click(function(){
$("p").hide();
});
});
$(document).ready(function(){
$("button").click(function(){
$("#div1").fadeIn();
$("#div2").fadeIn("slow");
$("#div3").fadeIn(3000);
});
});
<script>
$(document).ready(function(){
$("button").click(function(){
$("#div1").load("demo_test.txt");
});
});
</script>
<div id=“div1">
<h2>Let jQuery AJAX Change This Text</h2>
</div>
<button>Get External Content</button>
Making a better table in web browsers
Making interactive charts
Creating Data Driven Documents
Hosted Libraries
▪ You can download JavaScript libraries and keep on your site
▪ Or you can use a Hosted Library, such as Google’s
▪ read about it here https://developers.google.com/speed/
libraries/
<script src=“https://ajax.googleapis.com/ajax/libs/
jquery/2.1.4/jquery.min.js”></script>
▪ Some host their own library
<script src=“http://d3js.org/d3.v3.min.js">

</script>
<script src="http://code.highcharts.com/highcharts.js">

</script>
How to use SAS with JavaScript objects
▪ HTML 5 structures your page
▪ CSS 3 controls the look and feel
▪ JavaScript handles the interactivity
▪ Data typically either hard-coded or provided in JSON,
CSV, TSV, …
▪ SAS Stored Processes
▪ Provide the data in CSV or JSON format
▪ using data steps or PROC JSON
▪ Create and customise the HTML, CSS & JavaScript
▪ Using data steps or PROC STREAM
Use JSON with
Stored
Processes
5 of 6
What is JSON and why use it?
▪ Key-Value pairs
▪ Man and Machine readable
▪ Nested if necessary
▪ Used by many JavaScript objects
▪ Is a subset of JavaScript Object Notation, which is how
objects in JavaScript are built
▪ Sometimes XML or CSV can be used
▪ Very flexible
▪ can represent complex nested hierarchies of data
Lovely diagrams from Wikipedia
Example
{
"name": "Phil Mason",
"home": {
"town": "Wallingford",
"phone": 1491824891,
"current home": true,
"ages": [
51,
46,
18,
16,
13
]
}
}
Data Step to produce JSON
▪ Can run from a stored process
▪ Write to _webout to stream to browser
▪ Can define macros, to make it flexible and easy to repeat
▪ Can handle very complex & nested JSON
Example data step making JSON
data _null_ ;
set sashelp.class end=_end ;
if _n_=1 then put '[' ;
put '{' ;
put '"Name":"' name +(-1) '",' ;
put '"Sex":"' sex +(-1) '",' ;
put '"Age":"' age +(-1) '",' ;
put '"Height":"' height +(-1) '",' ;
put '"Weight":"' weight +(-1) '"' ;
put '}' ;
if not _end then put ',' ;
else put ']' ;
run ;
[
{
"Name":"Alfred",
"Sex":"M",
"Age":"14",
"Height":"69",
"Weight":"112.5"
}
,
{
"Name":"Alice",
"Sex":"F",
"Age":"13",
"Height":"56.5",
PROC JSON
▪ SAS 9.4
▪ Easily produces JSON from SAS datasets
▪ Can produce more complex JSON as well as simple
JSON
▪ Can use macros to write PROC JSON, making it very
flexible
PROC JSON
▪ Minimum code needed
▪ Produces default output
{
"SASJSONExport": "1.0",
"SASTableData+CLASS": [
{
"Name": "Alfred",
"Sex": "M",
"Age": 14,
"Height": 69,
"Weight": 112.5
},
{
"Name": "Alice",
"Sex": " F",
"Age": 13,
"Height": 56.5,
"Weight": 84
},
proc json out=temp ;
export sashelp.class ;
run ;
Better PROC JSON code
▪ Pretty - lays out the JSON clearly
▪ noSAStags - leaves out SAS metadata from the JSON
proc json out='/tmp/class.json' pretty nosastags ;
export sashelp.class ;
run ;
[
{
"Name": "Alfred",
"Sex": "M",
"Age": 14,
"Height": 69,
"Weight": 112.5
Produces this output
JavaScript
libraries with
SAS
6 of 6
PROC STREAM
▪ Processes text and expands macros within it
▪ Text is sent to an external file
▪ Can execute SAS code while processing the input stream
▪ using %sysfunc(dosub(fileref))
▪ Can include text into stream for processing
▪ using %include filleref
▪ Files can be read into stream, but macros not processed
▪ using &streamdelim readfile filref
▪ Newlines can be forced in output
▪ using &streamdelim newline
Simple example
%macro cols(n) ;
%do i=1 %to &n ;
<td>&i</td>
%end ;
%mend cols ;
filename out '/folders/myfolders/test.html' ;
proc stream outfile=out ;
BEGIN
<table>
<tr>%cols(4)</tr>
</table>
;;;;
<table><tr><td>1</td> <td>2</td> <td>3</td> <td>4</td></tr></table>
General Approach to make a new “Viz”
Find an example
▪ Pick a visualisation
▪ Close to something you want
▪ Could be changed to meet needs
▪ Could be combined with other things to meet needs
▪ Check it for suitability
▪ Some things are easier than others
▪ Is it free?
▪ Handle libraries
▪ Make sure you are pointing to a local copy or CDN
▪ Copy & Test locally
Number Display Example
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/crossfilter/1.3.11/crossfilter.min.js"></script>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/dc/1.7.3/dc.min.js"></script>
<script type="text/javascript" src="../js/d3.js"></script>
<script type="text/javascript" src="../js/crossfilter.js"></script>
<script type="text/javascript" src="../js/dc.js"></script>
http://dc-js.github.io/dc.js/examples/cust.html
Wrap in a Stored Process
▪ Write code to _WEBOUT using
▪ Data step
▪ Proc Stream
▪ Mixture of both
▪ Leave out the %stpbegin & %stpend macros
▪ Call using Stored Process Web Application from browser
http://server57562.uk2net.com/SASStoredProcess/do?_program=
%2FUser+Folders%2FPhil+Mason%2FMy+Folder%2Fd3+-+data+step
Use Proc Stream with PRESCOL
What should we change?
▪ Parameters
▪ So we can control what it does
▪ Data
▪ So it works using our data
▪ Libraries
▪ Often they point to resources on another web site
▪ Can copy to our web site
▪ Can use Content Delivery Network (CDN)
Parameters
▪ Identify anything we want to alter
▪ If it is a one time change, then make the change
▪ If we want to change it from run to run, then it is a
candidate for macros
▪ Identify anything we want to add, e.g. a title
Data
▪ Identify where the data is coming from
▪ What format is it in?
▪ We will need to make our data in same format
▪ Consider options for reproducing data
How to change things?
▪ Macro variables
▪ Replace shorter things we want to control
▪ Macro programs
▪ Replace longer things we want to control
▪ Make use of looping, conditions, dataset I/O, file I/O,
etc.
Change width and height to a macro variable
Add corresponding parameters to 

Stored Process
Use parms in call to Stored Process
http://server57562.uk2net.com/SASStoredProcess/do?_program=%2FUser
+Folders%2FPhil+Mason%2FMy+Folder%2Fd3+-+macroed&w=400&h=400
▪ Can just make a flat file
▪ Can make a stored process to deliver data
▪ Data Step
▪ Proc Stream
Make data into a CSV “file”
Make a Stored Process to deliver data
Modify Stored Process to use data from
Stored Process
▪ Use the d3.csv function to read in CSV data into a
JavaScript array.
▪ Remove the hard-coded data
▪ Add a call to load data
▪ All code needs to be inside function
▪ Finish off function call at the end with })
Stored Process using macro parms and
another Stored Process for data
Where have we go to?
▪ Stored Process for Program
▪ Creates HTML, JavaScript, CSS
▪ Stored Process for Data
▪ Produces a stream of CSV data
▪ Possibly copies of libraries on our Infrastructure
▪ CSS
▪ JavaScript
▪ We have a working little JavaScript/SAS Stored Process
Visualisation Web Application!
Next Steps
▪ Add more graphs to these 3 based on the same data
▪ Parameterise the data used
▪ Change variables too
▪ Make them all Stored Process parameters
▪ Therefore they are also macro variables
▪ Change Stored Process making data to be general
purpose by feeding a dataset name to it.
▪ Create several Stored Processes like this and combine
them to make a dashboard.
Repeat object(s) to make a Dashboard
▪ We don't have time for this, but basic steps are …
▪ Create a bunch of empty div sections in HTML 5
▪ perhaps just with a H1 so you can see them
▪ Make some CSS to lay them out how you like
▪ easy to do accordions, tabs, sliding layouts, etc.
▪ Use some jQuery to fill the div sections
▪ use Ajax calls to do it
▪ Possibly add some drop down selections lists, etc.
▪ Use jQuery to add info from there to your Ajax calls
▪ That’s about it!
Conclusion
Conclusions
▪ It’s easy to find great JavaScript visualisation software
▪ It’s easy to wrap it up and customise it with a Stored
Process
▪ It’s easy to feed it with data from another Stored Process
▪ Combine some of these into a dashboard or application
▪ Put it all together and you have yourself a powerful
cutting edge visualisation system.
Extras
Some great links to useful
resources
http://www.robslink.com/SAS/Home.htm
http://www.visualisingdata.com/index.php/
http://www.jsgraphs.com/
http://www.graphviz.org/Gallery.php
http://www.highcharts.com/demo
http://www.amcharts.com/demos/
https://github.com/mbostock/d3/wiki/Gallery
http://dc-js.github.io/dc.js/
Some great diagrams
Sas stored processes for creating great visualisations

Mais conteúdo relacionado

Semelhante a Sas stored processes for creating great visualisations

Magento Performance Optimization 101
Magento Performance Optimization 101Magento Performance Optimization 101
Magento Performance Optimization 101Angus Li
 
More efficient, usable web
More efficient, usable webMore efficient, usable web
More efficient, usable webChris Mills
 
Intro to SpringBatch NoSQL 2021
Intro to SpringBatch NoSQL 2021Intro to SpringBatch NoSQL 2021
Intro to SpringBatch NoSQL 2021Slobodan Lohja
 
Share point 2010_overview-day4-code
Share point 2010_overview-day4-codeShare point 2010_overview-day4-code
Share point 2010_overview-day4-codeNarayana Reddy
 
Share point 2010_overview-day4-code
Share point 2010_overview-day4-codeShare point 2010_overview-day4-code
Share point 2010_overview-day4-codeNarayana Reddy
 
Developing High Performance Web Apps - CodeMash 2011
Developing High Performance Web Apps - CodeMash 2011Developing High Performance Web Apps - CodeMash 2011
Developing High Performance Web Apps - CodeMash 2011Timothy Fisher
 
Developing High Performance Web Apps
Developing High Performance Web AppsDeveloping High Performance Web Apps
Developing High Performance Web AppsTimothy Fisher
 
Joomla in the cloud with Openshift
Joomla in the cloud with OpenshiftJoomla in the cloud with Openshift
Joomla in the cloud with OpenshiftEdoardo Schepis
 
SharePoint Object Model, Web Services and Events
SharePoint Object Model, Web Services and EventsSharePoint Object Model, Web Services and Events
SharePoint Object Model, Web Services and EventsMohan Arumugam
 
Future of Serverless
Future of ServerlessFuture of Serverless
Future of ServerlessYoav Avrahami
 
Turku loves-storybook-styleguidist-styled-components
Turku loves-storybook-styleguidist-styled-componentsTurku loves-storybook-styleguidist-styled-components
Turku loves-storybook-styleguidist-styled-componentsJames Stone
 
Theming Wordpress for Your Showcases
Theming Wordpress for Your ShowcasesTheming Wordpress for Your Showcases
Theming Wordpress for Your ShowcasesJun Hu
 
STSADM Automating SharePoint Administration - Tech Ed South East Asia 2008 wi...
STSADM Automating SharePoint Administration - Tech Ed South East Asia 2008 wi...STSADM Automating SharePoint Administration - Tech Ed South East Asia 2008 wi...
STSADM Automating SharePoint Administration - Tech Ed South East Asia 2008 wi...Joel Oleson
 
Workshop: Building Vaadin add-ons
Workshop: Building Vaadin add-onsWorkshop: Building Vaadin add-ons
Workshop: Building Vaadin add-onsSami Ekblad
 
Web II - 01 - Introduction to server-side development
Web II - 01 - Introduction to server-side developmentWeb II - 01 - Introduction to server-side development
Web II - 01 - Introduction to server-side developmentRandy Connolly
 
JavaScript Core fundamentals - Learn JavaScript Here
JavaScript Core fundamentals - Learn JavaScript HereJavaScript Core fundamentals - Learn JavaScript Here
JavaScript Core fundamentals - Learn JavaScript HereLaurence Svekis ✔
 

Semelhante a Sas stored processes for creating great visualisations (20)

Progressive Web Apps
Progressive Web AppsProgressive Web Apps
Progressive Web Apps
 
Magento Performance Optimization 101
Magento Performance Optimization 101Magento Performance Optimization 101
Magento Performance Optimization 101
 
JavaScripts & jQuery
JavaScripts & jQueryJavaScripts & jQuery
JavaScripts & jQuery
 
More efficient, usable web
More efficient, usable webMore efficient, usable web
More efficient, usable web
 
Intro to SpringBatch NoSQL 2021
Intro to SpringBatch NoSQL 2021Intro to SpringBatch NoSQL 2021
Intro to SpringBatch NoSQL 2021
 
Share point 2010_overview-day4-code
Share point 2010_overview-day4-codeShare point 2010_overview-day4-code
Share point 2010_overview-day4-code
 
Share point 2010_overview-day4-code
Share point 2010_overview-day4-codeShare point 2010_overview-day4-code
Share point 2010_overview-day4-code
 
Developing High Performance Web Apps - CodeMash 2011
Developing High Performance Web Apps - CodeMash 2011Developing High Performance Web Apps - CodeMash 2011
Developing High Performance Web Apps - CodeMash 2011
 
Developing High Performance Web Apps
Developing High Performance Web AppsDeveloping High Performance Web Apps
Developing High Performance Web Apps
 
Joomla in the cloud with Openshift
Joomla in the cloud with OpenshiftJoomla in the cloud with Openshift
Joomla in the cloud with Openshift
 
SharePoint Object Model, Web Services and Events
SharePoint Object Model, Web Services and EventsSharePoint Object Model, Web Services and Events
SharePoint Object Model, Web Services and Events
 
WSS And Share Point For Developers
WSS And Share Point For DevelopersWSS And Share Point For Developers
WSS And Share Point For Developers
 
Future of Serverless
Future of ServerlessFuture of Serverless
Future of Serverless
 
Turku loves-storybook-styleguidist-styled-components
Turku loves-storybook-styleguidist-styled-componentsTurku loves-storybook-styleguidist-styled-components
Turku loves-storybook-styleguidist-styled-components
 
Theming Wordpress for Your Showcases
Theming Wordpress for Your ShowcasesTheming Wordpress for Your Showcases
Theming Wordpress for Your Showcases
 
STSADM Automating SharePoint Administration - Tech Ed South East Asia 2008 wi...
STSADM Automating SharePoint Administration - Tech Ed South East Asia 2008 wi...STSADM Automating SharePoint Administration - Tech Ed South East Asia 2008 wi...
STSADM Automating SharePoint Administration - Tech Ed South East Asia 2008 wi...
 
Workshop: Building Vaadin add-ons
Workshop: Building Vaadin add-onsWorkshop: Building Vaadin add-ons
Workshop: Building Vaadin add-ons
 
Web II - 01 - Introduction to server-side development
Web II - 01 - Introduction to server-side developmentWeb II - 01 - Introduction to server-side development
Web II - 01 - Introduction to server-side development
 
Introducción al SharePoint Framework SPFx
Introducción al SharePoint Framework SPFxIntroducción al SharePoint Framework SPFx
Introducción al SharePoint Framework SPFx
 
JavaScript Core fundamentals - Learn JavaScript Here
JavaScript Core fundamentals - Learn JavaScript HereJavaScript Core fundamentals - Learn JavaScript Here
JavaScript Core fundamentals - Learn JavaScript Here
 

Último

Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...amitlee9823
 
April 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's AnalysisApril 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's Analysismanisha194592
 
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangaloreamitlee9823
 
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...amitlee9823
 
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Standamitlee9823
 
Midocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxMidocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxolyaivanovalion
 
Capstone Project on IBM Data Analytics Program
Capstone Project on IBM Data Analytics ProgramCapstone Project on IBM Data Analytics Program
Capstone Project on IBM Data Analytics ProgramMoniSankarHazra
 
DATA SUMMIT 24 Building Real-Time Pipelines With FLaNK
DATA SUMMIT 24  Building Real-Time Pipelines With FLaNKDATA SUMMIT 24  Building Real-Time Pipelines With FLaNK
DATA SUMMIT 24 Building Real-Time Pipelines With FLaNKTimothy Spann
 
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...amitlee9823
 
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...amitlee9823
 
➥🔝 7737669865 🔝▻ Thrissur Call-girls in Women Seeking Men 🔝Thrissur🔝 Escor...
➥🔝 7737669865 🔝▻ Thrissur Call-girls in Women Seeking Men  🔝Thrissur🔝   Escor...➥🔝 7737669865 🔝▻ Thrissur Call-girls in Women Seeking Men  🔝Thrissur🔝   Escor...
➥🔝 7737669865 🔝▻ Thrissur Call-girls in Women Seeking Men 🔝Thrissur🔝 Escor...amitlee9823
 
Detecting Credit Card Fraud: A Machine Learning Approach
Detecting Credit Card Fraud: A Machine Learning ApproachDetecting Credit Card Fraud: A Machine Learning Approach
Detecting Credit Card Fraud: A Machine Learning ApproachBoston Institute of Analytics
 
➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men 🔝malwa🔝 Escorts Ser...
➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men  🔝malwa🔝   Escorts Ser...➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men  🔝malwa🔝   Escorts Ser...
➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men 🔝malwa🔝 Escorts Ser...amitlee9823
 
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 nightCheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 nightDelhi Call girls
 
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort ServiceBDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort ServiceDelhi Call girls
 
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Valters Lauzums
 
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...SUHANI PANDEY
 

Último (20)

Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get CytotecAbortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
 
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
 
April 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's AnalysisApril 2024 - Crypto Market Report's Analysis
April 2024 - Crypto Market Report's Analysis
 
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
 
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
 
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
 
Midocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxMidocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFx
 
Abortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Jeddah | +966572737505 | Get CytotecAbortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Jeddah | +966572737505 | Get Cytotec
 
Capstone Project on IBM Data Analytics Program
Capstone Project on IBM Data Analytics ProgramCapstone Project on IBM Data Analytics Program
Capstone Project on IBM Data Analytics Program
 
DATA SUMMIT 24 Building Real-Time Pipelines With FLaNK
DATA SUMMIT 24  Building Real-Time Pipelines With FLaNKDATA SUMMIT 24  Building Real-Time Pipelines With FLaNK
DATA SUMMIT 24 Building Real-Time Pipelines With FLaNK
 
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
 
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
 
➥🔝 7737669865 🔝▻ Thrissur Call-girls in Women Seeking Men 🔝Thrissur🔝 Escor...
➥🔝 7737669865 🔝▻ Thrissur Call-girls in Women Seeking Men  🔝Thrissur🔝   Escor...➥🔝 7737669865 🔝▻ Thrissur Call-girls in Women Seeking Men  🔝Thrissur🔝   Escor...
➥🔝 7737669865 🔝▻ Thrissur Call-girls in Women Seeking Men 🔝Thrissur🔝 Escor...
 
Detecting Credit Card Fraud: A Machine Learning Approach
Detecting Credit Card Fraud: A Machine Learning ApproachDetecting Credit Card Fraud: A Machine Learning Approach
Detecting Credit Card Fraud: A Machine Learning Approach
 
➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men 🔝malwa🔝 Escorts Ser...
➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men  🔝malwa🔝   Escorts Ser...➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men  🔝malwa🔝   Escorts Ser...
➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men 🔝malwa🔝 Escorts Ser...
 
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 nightCheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
 
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort ServiceBDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
 
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
 
Anomaly detection and data imputation within time series
Anomaly detection and data imputation within time seriesAnomaly detection and data imputation within time series
Anomaly detection and data imputation within time series
 
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
 

Sas stored processes for creating great visualisations

  • 1. SAS Stored Processes and Developing Web Applications Phil Mason Independent SAS Consultant SAS University Edition includes the SAS 9.4 products Base SAS®, SAS/STAT®, SAS/IML®, SAS/ACCESS® Interface to PC Files, and SAS® Studio. Runs in a Virtual Machine on PC, Mac or Linux. And you can download it for FREE!!! Did you know? http://www.sas.com/en_us/software/university-edition.html
  • 2. Contents ▪ Creating a Simple Web App using Enterprise Guide ▪ Make a report ▪ Turn it into a Stored Process ▪ Use Stored Process Web App ▪ Make a better Web App ▪ Add some HTML ▪ Add Java Script ▪ Make use of JavaScript libraries ▪ Identify a good visualisation ▪ Integrate with SAS Stored Processes
  • 4. Make a report ▪ Use Enterprise Guide ▪ Build a query
  • 7. Now you have a query
  • 9. Make a Stored Process
  • 15. Data Sources & Targets
  • 18. Stored Process ▪ Composed of: ▪ A metadata component ▪ A code component ▪ Alternative way to create a Stored Process ▪ Create the code with an editor ▪ In Management Console create the metadata/code
  • 19. Let’s take a quick look at Management Console
  • 22. Execution settings ▪ Select server to run it on ▪ Specify we want to stream output and that we can produce a package ▪ Keep code in metadata
  • 25. Run it via Enterprise Guide
  • 26. Edit a Stored Process with Management Console ▪ Find the one you want and double click it
  • 34. Stored Process Web Application ▪ Comes with Integration Technologies ▪ Needs some configuring, including a Web Application Server ▪ Allows running a stored process ▪ From a web browser ▪ From any other place where you can use a URL ▪ e.g. An application such as EXCEL, MS Word ▪ Parameters passed on URL appear as macro variables to Stored Process ▪ This is a great feature!
  • 35. Stored process web application
  • 36. Get a menu down left
  • 37. Run stored process from web app
  • 38. Run stored process from browser
  • 39. Run stored process from excel
  • 40. Open one to run it
  • 41. Results of run appear in EXCEL
  • 42. Add a Graph to Stored Process
  • 45. Add prompt for macro parameter added
  • 46. Stored Process using parameter via prompt
  • 47. URL showing parameter passed http://my.server/SASStoredProcess/do?
 _program=/Shared Data/SASTesting/ Test3&product_line=Children http://my.server/SASStoredProcess/do?
 _program=%2FShared+Data%2FSASTesting%2F Test3&product_line=Children Encoded
  • 49. Make a better Web App ▪ Use some HTML ▪ Gives us some more control ▪ Use some JavaScript ▪ Great for adding more interactivity ▪ Allows programming to control User Interface
  • 50. Simple HTML <html> <body> <h1>Pick a report to run</h1> <a href="http://my.server/SASStoredProcess/do? _program=%2FShared+Data%2FSASTesting%2FTest3 &product_line=Children"> Children</a><p> <a href="http://my.server/SASStoredProcess/do? _program=%2FShared+Data%2FSASTesting%2FTest3 &product_line=Clothes+%26+Shoes">Clothes & Shoes</a><p> <a href="http://my.server/SASStoredProcess/do? _program=%2FShared+Data%2FSASTesting%2FTest3 &product_line=Outdoors">Outdoors</a><p> <a href="http://my.server/SASStoredProcess/do?_program=%2FShared+Data %2FSASTesting%2FTest3 &product_line=Sports">Sports</a><p> </body> </html>
  • 52. Report shown in browser
  • 53. Using a form to run a Stored Process ▪ HTML form is great for making User Interfaces ▪ Form tag ▪ Make the first part of URL ▪ Input tag, using different type settings ▪ Text – fields for text ▪ Password – passwords where text is hidden ▪ Radio – radio buttons ▪ Checkbox – check boxes ▪ Submit – submit buttons to execute URL using parts of form
  • 56. Writing directly from Stored Process to browser ▪ _webout ▪ Reserved fileref for writing from Stored Process to browser ▪ %stpbegin macro sends output from procs to _webout ▪ %stpend stops output going to _webout ▪ Can write from a datastep to _webout ▪ Best to turn automatic Stored Process macros off
  • 57. New stored process to write HTML
  • 59. Add iFrame to keep output on same page
  • 60. Now menu & output on same page
  • 61. Useful optional parameters for Stored Processes ▪ _odsdest – lets us choose an ODS destination for type of output produced ▪ Switch between HTML, RTF, PDF, EXCEL, etc. ▪ _odsstyle – choose an ODS style ▪ _debug – can produce the SAS log, execution times, etc. ▪ _debug=log,time ▪ _debug=2179 … this is my favourite
  • 62. Define a dropdown menu for type of output
  • 63. Output type is added to menu
  • 64. HTML Headers ▪ Set headers in HTML from stored process ▪ Indicates what browser should do ▪ RTF ▪ EXCEL rc = stpsrv_header("Content-type", "application/msword") ; rc = stpsrv_header('Content-disposition','attachment; filename=test.rtf'); rc = stpsrv_header("Content-type", "application/pdf") ; rc = stpsrv_header('Content-disposition','attachment; filename=test.pdf');
  • 66. Define dropdown for ODS style
  • 67. Here is what 2 ODS style selections produce
  • 69. After report we get the log
  • 70. After log we get time
  • 71. Parts of URL for stored process call http://khv-sas-iis.cfsi.local/ SASStoredProcess/do? _program=%2FShared+Data%2FSASTesting %2FTest3
 &product_line=Children &_odsdest=html &_odsstyle=meadow &_debug=log &_debug=time
  • 73. Use automatic macro variables ▪ Construct a URL using: ▪ &_srvname ▪ &_srvport ▪ &_url
  • 74. What’s good about this technique ▪ Easily make SAS code run from a web browser ▪ Generate HTML, Excel, PDF or RTF easily. ▪ Easily add parameters making it much more flexible ▪ Build up a multiple page Web Application
  • 75. What’s not so good ▪ Tables and graphs don’t look as good as they could ▪ Can improve their look with some more work within SAS ▪ Tables lack some functionality ▪ Cant sort columns ▪ Slow using lots of data ▪ Table headers are not fixed, so they will scroll away if tables are long ▪ Only some basic widgets available for building a UI ▪ Only basic use of mouse for selecting
  • 76. Adding some JavaScript for interactivity ▪ onLoad – execute when page finishes loading ▪ onUnload – execute when page closes ▪ onKeyPress – execute when a key is pressed ▪ onKeyUp – execute when a key is released ▪ onMouseOver – execute when mouse is over something ▪ onMouseOut - … when mouse moves away ▪ onMouseDown … when left button is pressed ▪ onMouseUp … when left button is released ▪ onClick … when left button is clicked ▪ onDblClick … when left button is double clicked
  • 77. JavaScript Demo ▪ Lets see some of those things… ▪ Note: not all browsers support all JavaScript (in the same way) ▪ Try things out in all the browsers you might use
  • 78. <html> <head> <script type='text/javascript'> var popwin = null; function open_popup() { if (popwin == null) popwin = window.open( 'http://www.google.com', '', 'top=150, left=350, width=250, height=50, status=0, toolbar=0, location=0, menubar=0, directories=0, resizable=0, scrollbars=0' ); } function close_popup() { if (popwin != null) { popwin.close(); popwin = null; } } function checkKey() { var key = String.fromCharCode( window.event.keyCode); if (key == 'X') { alert( "You pressed the X key" ); } } </script> Some added JavaScript for extra functionality
  • 79. JavaScript providing more interactivity </head> <body onload='alert("finished loading");' onunload='alert("finished unloading");' onkeypress='window.status="key pressed is: " + String.fromCharCode(window.event.keyCode) ;' onkeyup='window.status="key up"; checkKey() ;'> Pop-up a window with information by moving over <a href='#' onmouseover='open_popup(); window.status="Hovering over the link" ; return true ;' onmouseout='close_popup(); window.status=" " ; return true ;'>here</a>. <p>Pop-up a window with information by holding mouse button down <a href='#' onmousedown='open_popup();' onmouseup='close_popup();'>here</a>. <p><a href='#' ondblclick='open_popup();'>Double click to open</a>, <a href='#' onclick='close_popup();'>single click to close here</a>. <p><a href='#' style='font-size="x-large"' onmousemove='open_popup();'>Move mouse over this to open</a>, <a style='font-size="x-large"' href='#' onmousemove='close_popup();'>move over this to close</a>. <p>Press <b>X</b> to make an alert window pop up. <p>Hold down a key to see what it is in the status bar. </body> </Html>
  • 80. Stored Process generates HTML Some excerpts… <form method="get" action="http://khv-sas-iis2.cfsi.local/SASStoredProcess/do?" target="content"> <select name="_program"> <option value="/Shared Data/SASTesting/cabotCollectionsDashboard">Month to Date</option> <option value="/Shared Data/SASTesting/ccDashDaily">Daily</option> <option value="/Shared Data/SASTesting/ccDashYTD">Year to Date</option> </select> <input type="checkbox" name="_debug" value="log">Show log<nbsp><nbsp><nbsp> <input type="checkbox" name="_debug" value="time">Show time taken<nbsp> <input type="checkbox" name="inline" value="1">Inline?<nbsp> <input type="submit" value="Run"><br>
  • 81. More excerpts of HTML organisationName <select name="organisationName" onchange="this.form.submit();"> <option value="Cabot Debt Purchase " selected>Cabot Debt Purchase </option> <option value="Cabot Stratford Serviced ">Cabot Stratford Serviced </option> </select> </form> <iframe name="content" height="85%" width="100%"> </iframe> </body> </html>
  • 83. A few good JavaScript libraries ▪ jQuery ▪ Write less, do more ▪ HandsOnTable or EasyUI ▪ Excel-like spreadsheet for Apps ▪ HighCharts ▪ Create interactive web charts easily ▪ D3 ▪ Data Driven Documents
  • 84. Manipulating your web page ▪ jQuery makes it easy to select parts of your page and attach functionality $(document).ready(function(){ $("button").click(function(){ $("p").hide(); }); }); $(document).ready(function(){ $("button").click(function(){ $("#div1").fadeIn(); $("#div2").fadeIn("slow"); $("#div3").fadeIn(3000); }); }); <script> $(document).ready(function(){ $("button").click(function(){ $("#div1").load("demo_test.txt"); }); }); </script> <div id=“div1"> <h2>Let jQuery AJAX Change This Text</h2> </div> <button>Get External Content</button>
  • 85. Making a better table in web browsers
  • 87. Creating Data Driven Documents
  • 88. Hosted Libraries ▪ You can download JavaScript libraries and keep on your site ▪ Or you can use a Hosted Library, such as Google’s ▪ read about it here https://developers.google.com/speed/ libraries/ <script src=“https://ajax.googleapis.com/ajax/libs/ jquery/2.1.4/jquery.min.js”></script> ▪ Some host their own library <script src=“http://d3js.org/d3.v3.min.js">
 </script> <script src="http://code.highcharts.com/highcharts.js">
 </script>
  • 89. How to use SAS with JavaScript objects ▪ HTML 5 structures your page ▪ CSS 3 controls the look and feel ▪ JavaScript handles the interactivity ▪ Data typically either hard-coded or provided in JSON, CSV, TSV, … ▪ SAS Stored Processes ▪ Provide the data in CSV or JSON format ▪ using data steps or PROC JSON ▪ Create and customise the HTML, CSS & JavaScript ▪ Using data steps or PROC STREAM
  • 91. What is JSON and why use it? ▪ Key-Value pairs ▪ Man and Machine readable ▪ Nested if necessary ▪ Used by many JavaScript objects ▪ Is a subset of JavaScript Object Notation, which is how objects in JavaScript are built ▪ Sometimes XML or CSV can be used ▪ Very flexible ▪ can represent complex nested hierarchies of data
  • 92. Lovely diagrams from Wikipedia
  • 93. Example { "name": "Phil Mason", "home": { "town": "Wallingford", "phone": 1491824891, "current home": true, "ages": [ 51, 46, 18, 16, 13 ] } }
  • 94. Data Step to produce JSON ▪ Can run from a stored process ▪ Write to _webout to stream to browser ▪ Can define macros, to make it flexible and easy to repeat ▪ Can handle very complex & nested JSON
  • 95. Example data step making JSON data _null_ ; set sashelp.class end=_end ; if _n_=1 then put '[' ; put '{' ; put '"Name":"' name +(-1) '",' ; put '"Sex":"' sex +(-1) '",' ; put '"Age":"' age +(-1) '",' ; put '"Height":"' height +(-1) '",' ; put '"Weight":"' weight +(-1) '"' ; put '}' ; if not _end then put ',' ; else put ']' ; run ;
  • 97. PROC JSON ▪ SAS 9.4 ▪ Easily produces JSON from SAS datasets ▪ Can produce more complex JSON as well as simple JSON ▪ Can use macros to write PROC JSON, making it very flexible
  • 98. PROC JSON ▪ Minimum code needed ▪ Produces default output { "SASJSONExport": "1.0", "SASTableData+CLASS": [ { "Name": "Alfred", "Sex": "M", "Age": 14, "Height": 69, "Weight": 112.5 }, { "Name": "Alice", "Sex": " F", "Age": 13, "Height": 56.5, "Weight": 84 }, proc json out=temp ; export sashelp.class ; run ;
  • 99. Better PROC JSON code ▪ Pretty - lays out the JSON clearly ▪ noSAStags - leaves out SAS metadata from the JSON proc json out='/tmp/class.json' pretty nosastags ; export sashelp.class ; run ; [ { "Name": "Alfred", "Sex": "M", "Age": 14, "Height": 69, "Weight": 112.5 Produces this output
  • 101. PROC STREAM ▪ Processes text and expands macros within it ▪ Text is sent to an external file ▪ Can execute SAS code while processing the input stream ▪ using %sysfunc(dosub(fileref)) ▪ Can include text into stream for processing ▪ using %include filleref ▪ Files can be read into stream, but macros not processed ▪ using &streamdelim readfile filref ▪ Newlines can be forced in output ▪ using &streamdelim newline
  • 102. Simple example %macro cols(n) ; %do i=1 %to &n ; <td>&i</td> %end ; %mend cols ; filename out '/folders/myfolders/test.html' ; proc stream outfile=out ; BEGIN <table> <tr>%cols(4)</tr> </table> ;;;; <table><tr><td>1</td> <td>2</td> <td>3</td> <td>4</td></tr></table>
  • 103. General Approach to make a new “Viz”
  • 104. Find an example ▪ Pick a visualisation ▪ Close to something you want ▪ Could be changed to meet needs ▪ Could be combined with other things to meet needs ▪ Check it for suitability ▪ Some things are easier than others ▪ Is it free? ▪ Handle libraries ▪ Make sure you are pointing to a local copy or CDN ▪ Copy & Test locally
  • 105. Number Display Example <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script> <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/crossfilter/1.3.11/crossfilter.min.js"></script> <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/dc/1.7.3/dc.min.js"></script> <script type="text/javascript" src="../js/d3.js"></script> <script type="text/javascript" src="../js/crossfilter.js"></script> <script type="text/javascript" src="../js/dc.js"></script> http://dc-js.github.io/dc.js/examples/cust.html
  • 106.
  • 107. Wrap in a Stored Process ▪ Write code to _WEBOUT using ▪ Data step ▪ Proc Stream ▪ Mixture of both ▪ Leave out the %stpbegin & %stpend macros ▪ Call using Stored Process Web Application from browser http://server57562.uk2net.com/SASStoredProcess/do?_program= %2FUser+Folders%2FPhil+Mason%2FMy+Folder%2Fd3+-+data+step
  • 108.
  • 109. Use Proc Stream with PRESCOL
  • 110. What should we change? ▪ Parameters ▪ So we can control what it does ▪ Data ▪ So it works using our data ▪ Libraries ▪ Often they point to resources on another web site ▪ Can copy to our web site ▪ Can use Content Delivery Network (CDN)
  • 111. Parameters ▪ Identify anything we want to alter ▪ If it is a one time change, then make the change ▪ If we want to change it from run to run, then it is a candidate for macros ▪ Identify anything we want to add, e.g. a title
  • 112. Data ▪ Identify where the data is coming from ▪ What format is it in? ▪ We will need to make our data in same format ▪ Consider options for reproducing data
  • 113. How to change things? ▪ Macro variables ▪ Replace shorter things we want to control ▪ Macro programs ▪ Replace longer things we want to control ▪ Make use of looping, conditions, dataset I/O, file I/O, etc.
  • 114.
  • 115. Change width and height to a macro variable
  • 116. Add corresponding parameters to 
 Stored Process
  • 117. Use parms in call to Stored Process http://server57562.uk2net.com/SASStoredProcess/do?_program=%2FUser +Folders%2FPhil+Mason%2FMy+Folder%2Fd3+-+macroed&w=400&h=400
  • 118. ▪ Can just make a flat file ▪ Can make a stored process to deliver data ▪ Data Step ▪ Proc Stream Make data into a CSV “file”
  • 119. Make a Stored Process to deliver data
  • 120. Modify Stored Process to use data from Stored Process ▪ Use the d3.csv function to read in CSV data into a JavaScript array. ▪ Remove the hard-coded data ▪ Add a call to load data ▪ All code needs to be inside function ▪ Finish off function call at the end with })
  • 121. Stored Process using macro parms and another Stored Process for data
  • 122. Where have we go to? ▪ Stored Process for Program ▪ Creates HTML, JavaScript, CSS ▪ Stored Process for Data ▪ Produces a stream of CSV data ▪ Possibly copies of libraries on our Infrastructure ▪ CSS ▪ JavaScript ▪ We have a working little JavaScript/SAS Stored Process Visualisation Web Application!
  • 123. Next Steps ▪ Add more graphs to these 3 based on the same data ▪ Parameterise the data used ▪ Change variables too ▪ Make them all Stored Process parameters ▪ Therefore they are also macro variables ▪ Change Stored Process making data to be general purpose by feeding a dataset name to it. ▪ Create several Stored Processes like this and combine them to make a dashboard.
  • 124. Repeat object(s) to make a Dashboard ▪ We don't have time for this, but basic steps are … ▪ Create a bunch of empty div sections in HTML 5 ▪ perhaps just with a H1 so you can see them ▪ Make some CSS to lay them out how you like ▪ easy to do accordions, tabs, sliding layouts, etc. ▪ Use some jQuery to fill the div sections ▪ use Ajax calls to do it ▪ Possibly add some drop down selections lists, etc. ▪ Use jQuery to add info from there to your Ajax calls ▪ That’s about it!
  • 126. Conclusions ▪ It’s easy to find great JavaScript visualisation software ▪ It’s easy to wrap it up and customise it with a Stored Process ▪ It’s easy to feed it with data from another Stored Process ▪ Combine some of these into a dashboard or application ▪ Put it all together and you have yourself a powerful cutting edge visualisation system.
  • 127. Extras
  • 128. Some great links to useful resources