sas stored processes and
play

SAS Stored Processes and Developing Web Applications Phil Mason - PowerPoint PPT Presentation

SAS Stored Processes and Developing Web Applications Phil Mason Independent SAS Consultant Contents Creating a Simple Web App using Enterprise Guide Make a report Turn it into a Stored Process Use Stored Process Web App Make


  1. 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>

  2. 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>

  3. Use JavaScript Libraries

  4. 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

  5. Manipulating your web page  jQuery makes it easy to select parts of your page and attach functionality $(document).ready(function(){ <script> $("button").click(function(){ $(document).ready(function(){ $("p").hide(); $("button").click(function(){ }); $("#div1").load("demo_test.txt"); }); }); }); </script> $(document).ready(function(){ $("button").click(function(){ <div id=“div1"> $("#div1").fadeIn(); <h2>Let jQuery AJAX Change This Text</h2> $("#div2").fadeIn("slow"); </div> $("#div3").fadeIn(3000); }); <button>Get External Content</button> });

  6. Making a better table in web browsers

  7. Making interactive charts

  8. Creating Data Driven Documents

  9. 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>

  10. 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

  11. Use JSON with Stored Processes

  12. 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

  13. Example { "name": "Phil Mason", "home": { "town": "Wallingford", "phone": 1491824891, "current home": true, "ages": [ 51, 46, 18, 16, 13 ] } }

  14. 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

  15. 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 ;

  16. [ { "Name":"Alfred", "Sex":"M", "Age":"14", "Height":"69", "Weight":"112.5" } , { "Name":"Alice", "Sex":"F", "Age":"13", "Height":"56.5",

  17. 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

  18. PROC JSON { "SASJSONExport": "1.0",  Minimum code needed "SASTableData+CLASS": [ {  Produces default output "Name": "Alfred", "Sex": "M", "Age": 14, "Height": 69, "Weight": 112.5 }, { proc json out=temp ; "Name": "Alice", export sashelp.class ; "Sex": " F", run ; "Age": 13, "Height": 56.5, "Weight": 84 },

  19. 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", Produces this output "Age": 14, "Height": 69, "Weight": 112.5 },

  20. JavaScript libraries with SAS

Recommend


More recommend