SAS ® Global Forum 2014 March Washington, DC
2 Paper PROC STREAM and SAS® Server Pages: Generating Custom User Interfaces Don Henderson Henderson Consulting Services, LLC
3 Custom User Interfaces Virtually every Stored Process (or SAS/IntrNet Application Dispatcher program) has parameters. They need to be captured in a User Interface and passed to the Stored Process. The SAS BI/EBI prompting model can be a useful tool. SAS/IntrNet has no such facility. For web-based applications, the default prompting model interface (in my experience) rarely satisfies the end-users look and feel and functionality needs. An alternative approach I’ve used on a number of projects is presented here.
4 Chaining Stored Processes Together Generating a custom user interface for a stored process (or a SAS/IntrNet Application Dispatcher program) can be accomplished by chaining two (or more) stored processes together. The first stored process generates the user interface where the user selects the desired options and uses the STREAM procedure with an input SAS Server Page to display the user interface. The second (or later) stored process in the chain generates the desired output.
5 An example – An Exploding Pie Chart
6 A Framework for Creating Custom Prompts The Framework presented here includes the following re-usable components: Two stored processes »The runMacro Stored Process. »The sasServerPage Stored Process. Two utility SAS Server Pages: »The stpHeader SAS Server Page. »The stpTrailer SAS Server Page. A library of utility macros – in a SAS autocall library.
7 The runMacro Stored Process The runMacro stored process has one required parameter: macroToRun - the name of the macro to run. See the sasCommunity.org article The runMacro Stored Process, for more details on this stored process.The runMacro Stored Process The name of the macro to run is passed as a parameter. Best Practice: register the sasServerPage and runMacro stored processes in the same metadata folder. They can reference each other using the &_metafolder macro variable created by the stored process server.&_metafolder
8 The runMacro Stored Process For the purposes of this paper, a very simple version of runMacro will be used: *ProcessBody; %stpbegin; %put NOTE: Execute macro ¯oToRun..; %¯oToRun %stpend; The name of the macro to run is passed as an input parameter. As a result, %¯oToRun resolves to a % sign followed by the macro name, thus invoking the specified macro.
9 The runMacro Stored Process The use of such a runMacro stored process can be a very powerful approach in a number of ways, for example: If you have lots of reports and want to make them available from the SAS Stored Process Server, you need not create a distinct stored process for each one – just save the macro source code in a autocall directory defined to your stored process server. Alternatively, if you have existing reports packaged as macros (or SAS programmers who are familiar with the SAS macro language), you can invoke the reports by using the runMacro stored process.
10 The sasServerPage Stored Process The sasServerPage stored process simply calls a macro called sasServerPage which invokes PROC STREAM using %include to define the input data stream (i.e., the SAS Server Page to be processed). This allows the macro to be called from other stored processes or programs as needed. For example, you might want to use the runMacro stored process so you can run a macro to set up the environments for the chained stored processes. That macro could then call the sasServerPage macro as its last step.
11 The sasServerPage Stored Process For the purposes of this paper, the source code used for the sasServerPage stored process is: *ProcessBody; %sasServerPage(fileref = &srvrpgs,page = &page,quoting = "ing,asis = &asis,noAbSSCmt = &noAbSSCmt ) The complete source code and description of the macro parameters is included in the paper for this presentation.
12 Utility SAS Server Pages Provides for the following functionality: Displays the output in the same window as the user interface. Toggles the user interface in order to maximize the amount of screen real estate for the output. Displays a processing image. Structure of the driver/calling SAS Server Page Assign parameter values %include the header The User Interface HTML %include the trailer The Drill Down example (presented later) inverts this. The SAS Server Page for the User Interface is passed in as a parameter
13 The stpHeader SAS Server Page The HTML and JavaScript necessary to implement: Displaying the output in the same window as the user interface. Toggling the user interface. The standard FORM fields for the Stored Process Server. Displaying the image to alert the user that the report is running. Has the following (macro variable) parameters: pageTitle – title for the generated HTML page. stpToRun – runMacro or sasServerPage. whatToRun – the macro or SAS Server page. Complete (sample) source code included in the paper.
14 The stpTrailer SAS Server Page Includes the HTML to: Close the FORM tag. Display any desired HTML at the bottom of the page. Like the stpHeader SAS Server Page: Complete (sample) source code included in the paper. Can be customized to suit the needs of your environment and stored processes. Could be repackaged as macros.
15 A library of utility macros Utility macros play an important role in building custom user interfaces. For example, macros that: Generate a pull down list (e.g., a select tag) of choices where the choices are populated from data in an input SAS data set. Generate either a series of checkboxes or radio buttons, again from the information in a SAS data set. Create a data set of distinct values that can be used to create a select tag or a series of checkboxes.
16 A library of utility macros My SAS Press book SAS Server Pages: Generating Dynamic Contact and my blog Jurassic SAS® in the BI/EBI World contain numerous other examples of such macros, as well as more complete/robust versions of the macros used here.SAS Server Pages: Generating Dynamic ContactJurassic SAS® in the BI/EBI World generateOptionTag generateCheckBoxes getDistinct summaryAsTree Convention: I like bumpy/ Camel case for my macros Best Practice: file names are lower case
17 Selected Examples Three examples will be presented: Generating a select tag for the user to select which product to include in a report. Generating a series of checkboxes for the user to select which products to include in a report. Prompting the user to select a drill down hierarchy for a summary data set. Thanks to the framework discussed here the html snippets for each of these examples is fairly simple. The complexities of the interface are built into the framework.
18 Generating a Select Tag
19 Generating a Select Tag The SAS Server Page that generates the UI. Use the framework header: %global pageTitle _debug stpToRun whatToRun; %let pageTitle=Products Select Tag; %let whatToRun=selectedProductsReport; &streamDelim;%include &srvrpgs(stpHeader.html);
20 Generating a Select Tag Create the specifics of the User Interface: %let rc = %sysfunc(dosubl(%nrbquote( %getDistinct(data=sashelp.shoes,vars=product,out=productList) ))); %generateOptionTag(data=productList,var=product,otherOptions=multiple size=&sqlobs ) Leverages utility macros available in an autocall library
21 Generating a Select Tag Define the standard footer html. &streamDelim;%include &srvrpgs(stpTrailer.html); Can be used for any number of things: Help/contact information. Disclaimers. Copyright statements. And so on.
22 The URL _program=/sspebook/sasServerPage&page=stpProductSelectTag Generating a Select Tag Lets run it!
23 Generating a Series of Checkboxes
24 Generating a Series of Checkboxes The SAS Server Page that generates the UI. Use the framework header (just like before): %global pageTitle _debug stpToRun whatToRun; %let pageTitle=Products Checkboxes; %let whatTorun=selectedProductsReport; &streamDelim;%include &srvrpgs(stpHeader.html);
25 Generating a Series of Checkboxes Create the specifics of the User Interface: %let rc = %sysfunc(dosubl(%nrbquote( proc sql noprint; select distinct cats('&streamDelim newline;<input type="checkbox"’,’ name="product" value="',strip(product), '">‘,strip(product) ) into:checkBoxes separated by ' ‘ from sashelp.shoes; quit; ))); &checkboxes
26 Generating a Series of Checkboxes Alternatively – use utility macros: %let rc = %sysfunc(dosubl(%nrbquote( %getDistinct(data=sashelp.shoes,vars=product,out=productList) ))); %generateCheckBoxes(data=productList,var=product )
27 Generating a Series of Checkboxes Define the standard footer html (exactly as before). &streamDelim;%include &srvrpgs(stpTrailer.html); Can be used for any number of things: Help/contact information. Disclaimers. Copyright statements. And so on.
28 Generating a Series of Checkboxes Lets run it! The URL _program=/sspebook/sasServerPage&page=stpProductCheckboxes
29 Select a Drill Down Hierarchy for a Data Set
30 Select a Drill Down Hierarchy for a Data Set The SAS Server Page that generates the UI. Use the framework header (almost just like before): %global pageTitle _debug stpToRun whatToRun; %let pageTitle=Summary Drill Down - a Tree View; %let stpToRun=sasServerPage; %let whatTorun=jqueryTreetable; &streamDelim;%include &srvrpgs(stpHeader.html);
31 Select a Drill Down Hierarchy for a Data Set Create the specifics of the User Interface: Select Hierarchy Region Subsidiary Product Region Product Subsidiary Product Region Subsidiary Product Region
32 Select a Drill Down Hierarchy for a Data Set This User Interface could be parameterized So the data set is not hard-coded To allow for the use of an already summarized data set Allowing the user to select and order the class variables Allowiing the user to select and order the analysis variables And so on....
33 Select a Drill Down Hierarchy for a Data Set Define the standard footer html (exactly as before). &streamDelim;%include &srvrpgs(stpTrailer.html); Can be used for any number of things: Help/contact information. Disclaimers. Copyright statements. And so on.
34 Select a Drill Down Hierarchy for a Data Set Lets run it! URL for a similar framework: ?_program=/sspebook/sasServerPage &page=ajaxContainer &formui=shoesdrillform.html
35 In Summary PROC STREAM is a very powerful new facility that extends the output that can be generated by SAS & facilitates for leveraging other web & HTML based facilities. The examples here only scratch the surface of what can be done with PROC STREAM (and SAS Server Pages). And check out the companion paper which provides an overview and addresses using PROC STREAM and SAS Server Pages in a batch environment: PROC STREAM and SAS Server Pages: Generating Custom HTML ReportsPROC STREAM and SAS Server Pages: Generating Custom HTML Reports
36 More on PROC STREAM Also Check Out: ebook SAS Server Pages: Generating Dynamic ContentSAS Server Pages: Generating Dynamic Content blog: Jurassic SAS® in the BI/EBI WorldJurassic SAS® in the BI/EBI World The full text for both of my papers can be found at My Papers and Presentations on sasCommunity.orgMy Papers and PresentationssasCommunity.org Watch those pages (requires a sasCommunity.org userid – which is free) if you want to be notified of changes or updates, e.g., Downloading the code from this presentation
37 Papers and Presentations on sasCommunity.org