Sas stored processes for creating great visualisations
-
Upload
phil-mason -
Category
Data & Analytics
-
view
1.053 -
download
3
Transcript of Sas stored processes for creating great visualisations
![Page 1: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/1.jpg)
SAS Stored Processes and Developing Web ApplicationsPhil 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
![Page 2: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/2.jpg)
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
![Page 3: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/3.jpg)
Make Report 1 of 6
![Page 4: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/4.jpg)
Make a report▪ Use Enterprise Guide ▪ Build a query
![Page 5: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/5.jpg)
Query Builder
![Page 6: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/6.jpg)
Query builder
![Page 7: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/7.jpg)
Now you have a query
![Page 8: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/8.jpg)
Make Stored Process
2 of 6
![Page 9: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/9.jpg)
Make a Stored Process
![Page 10: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/10.jpg)
Name it
![Page 11: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/11.jpg)
View code
![Page 12: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/12.jpg)
Pick Repository
![Page 13: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/13.jpg)
Librefs
![Page 14: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/14.jpg)
Prompts
![Page 15: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/15.jpg)
Data Sources & Targets
![Page 16: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/16.jpg)
Review
![Page 17: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/17.jpg)
Edit Stored Process
![Page 18: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/18.jpg)
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
![Page 19: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/19.jpg)
Let’s take a quick look at Management Console
![Page 20: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/20.jpg)
Create using Management Console
![Page 21: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/21.jpg)
Name it
![Page 22: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/22.jpg)
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
![Page 23: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/23.jpg)
Edit Source Code
![Page 24: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/24.jpg)
Define parameters
![Page 25: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/25.jpg)
Run it via Enterprise Guide
![Page 26: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/26.jpg)
Edit a Stored Process with Management Console
▪ Find the one you want and double click it
![Page 27: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/27.jpg)
Management Console
Name & Location
![Page 28: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/28.jpg)
Management Console
![Page 29: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/29.jpg)
Management Console
![Page 30: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/30.jpg)
Management Console
![Page 31: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/31.jpg)
Management Console
![Page 32: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/32.jpg)
Management Console
![Page 33: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/33.jpg)
Management Console
![Page 34: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/34.jpg)
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!
![Page 35: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/35.jpg)
Stored process web application
![Page 36: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/36.jpg)
Get a menu down left
![Page 37: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/37.jpg)
Run stored process from web app
![Page 38: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/38.jpg)
Run stored process from browser
![Page 39: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/39.jpg)
Run stored process from excel
![Page 40: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/40.jpg)
Open one to run it
![Page 41: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/41.jpg)
Results of run appear in EXCEL
![Page 42: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/42.jpg)
Add a Graph to Stored Process
![Page 43: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/43.jpg)
Result in web browser
![Page 44: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/44.jpg)
Add parameter
![Page 45: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/45.jpg)
Add prompt for macro parameter added
![Page 46: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/46.jpg)
Stored Process using parameter via prompt
![Page 47: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/47.jpg)
URL showing parameter passedhttp://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
![Page 48: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/48.jpg)
Enhance with HTML &
JavaScript 3 of 6
![Page 49: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/49.jpg)
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
![Page 50: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/50.jpg)
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>
![Page 51: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/51.jpg)
HTML Menu
![Page 52: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/52.jpg)
Report shown in browser
![Page 53: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/53.jpg)
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
![Page 54: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/54.jpg)
HTML using Form
![Page 55: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/55.jpg)
What’s displayed
![Page 56: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/56.jpg)
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
![Page 57: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/57.jpg)
New stored process to write HTML
![Page 58: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/58.jpg)
Stored process produces this
![Page 59: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/59.jpg)
Add iFrame to keep output on same page
![Page 60: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/60.jpg)
Now menu & output on same page
![Page 61: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/61.jpg)
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
![Page 62: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/62.jpg)
Define a dropdown menu for type of output
![Page 63: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/63.jpg)
Output type is added to menu
![Page 64: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/64.jpg)
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');
![Page 65: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/65.jpg)
RTF output
![Page 66: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/66.jpg)
Define dropdown for ODS style
![Page 67: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/67.jpg)
Here is what 2 ODS style selections produce
![Page 68: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/68.jpg)
Add some checkboxes
![Page 69: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/69.jpg)
After report we get the log
![Page 70: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/70.jpg)
After log we get time
![Page 71: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/71.jpg)
Parts of URL for stored process callhttp://khv-sas-iis.cfsi.local/SASStoredProcess/do? _program=%2FShared+Data%2FSASTesting%2FTest3 &product_line=Children &_odsdest=html &_odsstyle=meadow &_debug=log &_debug=time
![Page 72: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/72.jpg)
Useful automatic macro variables
![Page 73: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/73.jpg)
Use automatic macro variables▪ Construct a URL using: ▪ &_srvname ▪ &_srvport ▪ &_url
![Page 74: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/74.jpg)
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
![Page 75: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/75.jpg)
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
![Page 76: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/76.jpg)
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
![Page 77: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/77.jpg)
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
![Page 78: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/78.jpg)
<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
![Page 79: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/79.jpg)
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>
![Page 80: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/80.jpg)
Stored Process generates HTMLSome 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>
![Page 81: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/81.jpg)
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>
![Page 82: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/82.jpg)
Use JavaScript Libraries
4 of 6
![Page 83: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/83.jpg)
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
![Page 84: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/84.jpg)
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>
![Page 85: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/85.jpg)
Making a better table in web browsers
![Page 86: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/86.jpg)
Making interactive charts
![Page 87: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/87.jpg)
Creating Data Driven Documents
![Page 88: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/88.jpg)
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>
![Page 89: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/89.jpg)
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
![Page 90: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/90.jpg)
Use JSON with Stored
Processes 5 of 6
![Page 91: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/91.jpg)
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
![Page 92: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/92.jpg)
Lovely diagrams from Wikipedia
![Page 93: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/93.jpg)
Example{ "name": "Phil Mason", "home": { "town": "Wallingford", "phone": 1491824891, "current home": true, "ages": [ 51, 46, 18, 16, 13 ] } }
![Page 94: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/94.jpg)
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
![Page 95: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/95.jpg)
Example data step making JSONdata _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 ;
![Page 96: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/96.jpg)
[ { "Name":"Alfred", "Sex":"M", "Age":"14", "Height":"69", "Weight":"112.5" } , { "Name":"Alice", "Sex":"F", "Age":"13", "Height":"56.5", "Weight":"84"
![Page 97: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/97.jpg)
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
![Page 98: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/98.jpg)
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 ;
![Page 99: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/99.jpg)
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
![Page 100: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/100.jpg)
JavaScript libraries with
SAS 6 of 6
![Page 101: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/101.jpg)
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
![Page 102: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/102.jpg)
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>
![Page 103: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/103.jpg)
General Approach to make a new “Viz”
![Page 104: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/104.jpg)
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
![Page 105: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/105.jpg)
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
![Page 106: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/106.jpg)
![Page 107: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/107.jpg)
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
![Page 108: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/108.jpg)
![Page 109: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/109.jpg)
Use Proc Stream with PRESCOL
![Page 110: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/110.jpg)
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)
![Page 111: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/111.jpg)
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
![Page 112: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/112.jpg)
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
![Page 113: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/113.jpg)
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.
![Page 114: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/114.jpg)
![Page 115: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/115.jpg)
Change width and height to a macro variable
![Page 116: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/116.jpg)
Add corresponding parameters to Stored Process
![Page 117: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/117.jpg)
Use parms in call to Stored Processhttp://server57562.uk2net.com/SASStoredProcess/do?_program=%2FUser+Folders%2FPhil+Mason%2FMy+Folder%2Fd3+-+macroed&w=400&h=400
![Page 118: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/118.jpg)
▪ Can just make a flat file ▪ Can make a stored process to deliver data ▪ Data Step ▪ Proc Stream
Make data into a CSV “file”
![Page 119: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/119.jpg)
Make a Stored Process to deliver data
![Page 120: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/120.jpg)
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 })
![Page 121: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/121.jpg)
Stored Process using macro parms and another Stored Process for data
![Page 122: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/122.jpg)
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!
![Page 123: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/123.jpg)
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.
![Page 124: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/124.jpg)
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!
![Page 125: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/125.jpg)
Conclusion
![Page 126: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/126.jpg)
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.
![Page 127: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/127.jpg)
Extras
![Page 128: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/128.jpg)
Some great links to useful resources
![Page 137: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/137.jpg)
Some great diagrams
![Page 138: Sas stored processes for creating great visualisations](https://reader033.fdocuments.in/reader033/viewer/2022061308/58a455561a28ab55068b5e45/html5/thumbnails/138.jpg)