SAS ® Global Forum 2014 March 23-26 Washington, DC.

Slides:



Advertisements
Similar presentations
Introduction to Web Design Lecture number:. Todays Aim: Introduction to Web-designing and how its done. Modelling websites in HTML.
Advertisements

WEB DESIGN TABLES, PAGE LAYOUT AND FORMS. Page Layout Page Layout is an important part of web design Why do you think your page layout is important?
1 CSC 551: Web Programming Spring 2004 client-side programming with JavaScript  scripts vs. programs  JavaScript vs. JScript vs. VBScript  common tasks.
The Web Warrior Guide to Web Design Technologies
CHAPTER 30 THE HTML 5 FORMS PROCESSING. LEARNING OBJECTIVES What the three form elements are How to use the HTML 5 tag to specify a list of words’ form.
Intermediate Level Course. Text Format The text styles, bold, italics, underlining, superscript and subscript, can be easily added to selected text. Text.
1 HTML Markup language – coded text is converted into formatted text by a web browser. Big chart on pg. 16—39. Tags usually come in pairs like – data Some.
Session 6 Server-side programming - ASP. An ASP page is an HTML page interspersed with server-side code. The.ASP extension instead of.HTM denotes server-side.
Creating Web Page Forms. Objectives Describe how Web forms can interact with a server-based program Insert a form into a Web page Create and format a.
Tutorial 6 Working with Web Forms
Guide To UNIX Using Linux Third Edition
Creating Web Page Forms
2440: 141 Web Site Administration Web Server-Side Programming Professor: Enoch E. Damson.
Web Development & Design Foundations with XHTML Chapter 9 Key Concepts.
1 Web Developer & Design Foundations with XHTML Chapter 6 Key Concepts.
JAVASCRIPT HOW TO PROGRAM -2 DR. JOHN P. ABRAHAM UTPA.
DHTML. What is DHTML?  DHTML is the combination of several built-in browser features in fourth generation browsers that enable a web page to be more.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
4-Sep-15 HTML Forms Mrs. Goins Web Design Class. Parts of a Web Form A Form is an area that can contain Form Control/Elements. Each piece of information.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
XP Tutorial 6New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Creating Web Page Forms Designing a Product Registration Form Tutorial.
Forms and Form Controls Chapter What is a Form?
_______________________________________________________________________________________________________________ E-Commerce: Fundamentals and Applications1.
CS346 - Javascript 1, 21 Module 1 Introduction to JavaScript CS346.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
ULI101 – XHTML Basics (Part II) What is Markup Language? XHTML vs. HTML General XHTML Rules Block Level XHTML Tags XHTML Validation.
PMS /134/182 HEX 0886B6 PMS /39/80 HEX 5E2750 PMS /168/180 HEX 00A8B4 PMS /190/40 HEX 66CC33 By Adrian Gardener Date 9 July 2012.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
XP Mohammad Moizuddin Creating Web Pages with HTML Tutorial 1 1 New Perspectives on Creating Web Pages With HTML Tutorial 1: Developing a Basic Web Page.
 This presentation introduces the following: › 3 types of CSS › CSS syntax › CSS comments › CSS and color › The box model.
1 In the good old days... Years ago… the WWW was made up of (mostly) static documents. –Each URL corresponded to a single file stored on some hard disk.
Introduction to Applets CS 3505 Client Side Scripting with applets.
Lecture # 6 Forms, Widgets and Event Handling. Today Questions: From notes/reading/life? Share Personal Web Page (if not too personal) 1.Introduce: How.
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
PowerBuilder Online Courses - by Prasad Bodepudi
Website Development with PHP and MySQL Saving Data.
HTML Forms.
1 © Copyright 2000 Ethel Schuster The Web… in 15 minutes Ethel Schuster
HTML Basics BCIS 3680 Enterprise Programming. Web Client/Server Architecture 2  Your browser (the client) requests a Web page from a remote computer.
4 Chapter Four Introduction to HTML. 4 Chapter Objectives Learn basic HTML commands Discover how to display graphic image objects in Web pages Create.
Tutorial 6 Working with Web Forms. XP Objectives Explore how Web forms interact with Web servers Create form elements Create field sets and legends Create.
Tutorial 6 Working with Web Forms. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Explore how Web forms interact with.
1 HTML Forms
Chapter 2: Variables, Functions, Objects, and Events JavaScript - Introductory.
Creating a simple database This shows you how to set up a database using PHPMyAdmin (installed with WAMP)
Web Design and Development. World Wide Web  World Wide Web (WWW or W3), collection of globally distributed text and multimedia documents and files 
CSD 340 (Blum)1 Starting JavaScript Homage to the Homage to the Square.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Tutorial 6 Working with Web Forms. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Explore how Web forms interact with.
DT228/3 Web Development JSP: Actions elements and JSTL.
Department of Computer Science, Florida State University CGS 3066: Web Programming and Design Spring
1 CSC160 Chapter 1: Introduction to JavaScript Chapter 2: Placing JavaScript in an HTML File.
Based on Learning SAS by Example: A Programmer’s Guide Chapters 1 & 2
HTML Tutorial. What is HTML HTML is a markup language for describing web documents (web pages) HTML documents are described by HTML tags Each HTML tag.
SAS ® Global Forum 2014 March Washington, DC.
HTML Structure II (Form) WEEK 2.2. Contents Table Form.
Working Efficiently with Large SAS® Datasets Vishal Jain Senior Programmer.
Using the Macro Facility to Create HTML, XML and RTF output Rick Langston, SAS Institute Inc.
XP Tutorial 6New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Creating Web Page Forms Designing a Product Registration Form Tutorial 6.
2440: 141 Web Site Administration Web Forms Instructor: Joseph Nattey.
Module 1 Introduction to JavaScript
Mail Merge for Lotus Notes and Excel User Guide
Loops BIS1523 – Lecture 10.
Basic XHTML Tables XHTML tables—a frequently used feature that organizes data into rows and columns. Tables are defined with the table element. Table.
Intro to PHP & Variables
Introduction to JavaScript
A second look at JavaScript
WEB PROGRAMMING JavaScript.
Presentation transcript:

SAS ® Global Forum 2014 March Washington, DC

2 Paper PROC STREAM and SAS® Server Pages: Generating Custom HTML Reports Don Henderson Henderson Consulting Services, LLC

3 PROC STREAM and SAS Server Pages  What are they/What can they do?  Lots of things.  For example, very custom data driven web content.  Uses the Macro Language to conditionally and dynamically generate content.  Conceptually similar to what ASP and JSP pages do.  Can be used in batch SAS as well as SAS BI/EBI and SAS/IntrNet.

4 Some Examples (details later) A mail merge A tag cloud A clickable calendar

5 SAS Server Pages  Introduced in my SAS Press Book: Building Web Applications with SAS/IntrNet: A Guide to the Application Dispatcher.  Leveraged the RESOLVE function in the DATA step to process Macro Variable references and Macro calls.  Functional, but rudimentary.  PROC STREAM greatly expands what can be done with SAS Server Pages.

6 SAS Server Pages and PROC STREAM  The DATA Step 32K limit removed.  %INCLUDE to do what JSP and ASP applications refer to as Server-Side Includes.  SAS code can be defined and executed inside of an input SAS Server Page. Both SAS code to be executed as well as markup text (such as HTML, CSV, XML, and more) can be included.  SAS and many SCL functions (e.g., OPEN, CLOSE, FETCH, GETVARC, GETVARN, and so on) to access data.

7 THE SAS MACRO LANGUAGE A TEXT PROCESSING LANGUAGE  Macro Variables for Text Substitution.  Macros for Iterative and Conditional Text Generation.  Including Text from External Files.  Generating Dynamic Content from a SAS Data Set.  Executing SAS Code in a PROC STREAM Input File.

8 Macro Variables for Text Substitution  This first example illustrates a few key features:  Macro variable references are resolved (&SYSUSERID).  The %SYSFUNC macro function is used to execute functions, including the formatting of the result.  The output, by default, is streamed to the client in such a way that line feeds, extra spaces, and so on, are not included.

9 Macro Variables for Text Substitution

10 Macro Variables for Text Substitution proc stream outfile=_webout; BEGIN Hello World Hello &sysuserid.. This welcome note generated at %sysfunc(time(),timeampm8.) on %sysfunc(date(),monname.) %sysfunc(date(),day.). ;;;; run;

11 Macro Variables for Text Substitution Add the ASIS (aka PRESCOL) option

12 Macro Variables for Text Substitution Better – use &streamDelim newline;

13 Macro Variables for Text Substitution proc stream outfile=_webout; BEGIN &streamDelim newline; Hello World &streamDelim newline; &streamDelim newline; Hello &sysuserid.. &streamDelim newline; This welcome note generated at %sysfunc(time(),timeampm8.) on %sysfunc(date(),monname.) %sysfunc(date(),day.). &streamDelim newline; &streamDelim newline; ;;;; run;

14 Macros for Iterative and Conditional Text Generation  This next example (which could be written in any scripting language) highlights:  HTML text inline along with SAS macro language statements to control the generated HTML text.  Generating HTML (table rows) using a %DO loop.  Executing SAS functions using the %SYSFUNC and %QSYSFUNC macro functions.  Providing complete control over such HTML content as colors and table attributes. Note that some of the values are hardcoded (the table cell width), while others are macro parameters.

15 Macros for Iterative and Conditional Text Generation Note the use of HTML Entities

16 Macros for Iterative and Conditional Text Generation – The PROC STREAM code proc stream outfile=_webout; BEGIN %characterSet(evenRowBGColor=white,oddRowBGColor=grey) ;;;; Note the macro call

17 Macros for Iterative and Conditional Text Generation – The characterSet Macro %macro characterSet (evenRowBGColor = grey,oddRowBGColor = white ); %local i bgcolor char;.

18 Macros for Iterative and Conditional Text Generation – The characterSet Macro Character Entity References /* Define the style to use for the table cells so that the values need not be specified for each cell. */ td {text-align:center; width:100px;} th {text-align:center; width:100px;}.

19 Macros for Iterative and Conditional Text Generation – The characterSet Macro /* Define table header information */ Decimal Value ASCII Character Numeric Character Reference as Displayed Numeric Character Reference Coded Value. Could have been Parameterized.

20 Macros for Iterative and Conditional Text Generation – The characterSet Macro /* Use a macro %DO loop to generate the values from 32 to 255. Start at 32 - unprintable values below 32 can cause problems) */ %do i = 32 %to 255; %if &bgcolor ne &oddRowBGColor %then %let bgcolor = &oddRowBGColor; %else %let bgcolor = &evenRowBGColor;. Alternating Background colors Parameterized.

21 Macros for Iterative and Conditional Text Generation – The characterSet Macro &i %let char = %qsysfunc(byte(&i)); &char &#%qsysfunc(putn(&i,z3.)); /* The “Numeric Character Reference as Displayed” column is generated by prefixing &# to the decimal value. The “Numeric Character Reference Coded Value” uses & as the prefix instead of &, so the coded valued is displayed by the browser. */ &#%qsysfunc(putn(&i,z3.)); %end;... Note the /* */ Style comments.

22 Macros for Iterative and Conditional Text Generation – The characterSet Macro %mend characterSet; Close out the HTML and the Macro.

23 Including Text from External Files  The examples shown so far have used inline text to be processed by PROC STREAM inline. Typically, however, the input text will be in an external file. The syntax for including an external file is: &streamDelim; %include [file-specification];  Revised PROC STREAM call: proc stream outfile=_webout; BEGIN &streamDelim; %include srvrpgs(characterSet.html); ;;;; A Best Practice: Aggregate Syntax

24 Including Text from External Files Scroll bars.

25 Generating Dynamic Content from a SAS Data Set  So far, we have used the %SYSFUNC/%QSYSFUNC macro functions to execute SAS or SCL functions.  They can be used to access SAS data sets.  Allows SAS code and specifically SAS macros used in the input stream to PROC STREAM to access data set information (both attributes and data).  Thus, PROC STREAM can generate data-driven HTML content without requiring the generation of any SAS DATA or PROC step code.

26 Generating Dynamic Content from a SAS Data Set /* use a macro variable to define the subset of data to be read */ %let subsid = Addis Ababa; proc stream outfile=_webout quoting=single; BEGIN %delimited (data=sashelp.shoes,where=subsidiary=:"&subsid" ) ;;;; run;

27 Generating Dynamic Content from a SAS Data Set

28 Generating Dynamic Content from a SAS Data Set  This example highlights several other (beyond accessing SAS data) important features of PROC STREAM:  QUOTING=SINGLE option treats ' as a character and does not consider it to be the delimiter for a quoted string.  The program uses &streamDelim newline; to start each row of data on a new line. New lines are important in text files such as CSV files.  The importance of utility macros (defined in an autocall library) that perform common functions.

29 Generating Dynamic Content from a SAS Data Set  Admittedly, there are tons of ways to generate CSV files in SAS. The reason for generating a CSV file in this example was to highlight that any text file could be created.  For example, you could write a macro the generate a SAS program that is then saved.  Lots more examples in my SAS Press e-book and blog.

30 Executing SAS Code in a PROC STREAM Input File  The facility to include SAS code that is to be executed by PROC STREAM can be an important feature.  An additional level of abstraction incorporates generic routines (aka macro calls) within a SAS Server Page to perform specific types of functions.  For example creating a data set of distinct values for a column in a SAS data set in order to create a dynamic selection list.  A PROC STREAM program (e.g., a macro or stored process) with different input files (e.g., using %INCLUDE) where the name of the input file is macro variable/parameter.

31 Executing SAS Code in a PROC STREAM Input File  Consider an example of generating a selection list. proc stream outfile=_webout quoting=both; BEGIN Select Products proc sql noprint; select distinct '<input type="checkbox" name="product" value="' |strip(product)||'">'||strip(product) into:checkboxes separated by ' ' from sashelp.shoes; quit; &checkboxes ;;;; run;

32 Executing SAS Code in a PROC STREAM Input File  Output is not what we expected/wanted  PROC STREAM treated the SAS code as text to be included in the output file.

33 Executing SAS Code in a PROC STREAM Input File  Need to use the new DOSUB/DOSUBL function.  DOSUB: a single argument that is a fileref that contains SAS code to be executed.  DOSUBL: a single character argument that is the SAS code to be executed. %let rc = %sysfunc(dosubl( SAS Code - potentially spanning multiple lines ));  Best Practice: Use a macro call or %include instead of a long string of text which is the SAS Code.

34 Executing SAS Code in a PROC STREAM Input File  Changes to the previous PROC STREAM input stream.. %let rc =%sysfunc(dosubl( proc sql noprint;. quit; ));

35 Selected Examples  A sample mail-merge application.  Creating a custom (clickable) calendar.  Displaying data graphically, e.g., the use of Tag Clouds as an alternative to bar or pie charts.  Numerous additional examples are available in my:  SAS Press book: SAS Server Pages: Generating Dynamic ContactSAS Server Pages: Generating Dynamic Contact  Blog: Jurassic SAS® in the BI/EBI World”Jurassic SAS® in the BI/EBI World

36 A sample mail-merge application  Generate custom content for each defined subset of data, usually each observation in a data set. Such observations can be individual observations in a SAS data set or aggregated summary statistics for each value of a class variable, e.g.,  a custom formatted report for each department or product.  a case report form for clinical trials data.  and more.  This example: create a i.e., a letter as an HTML file for each observation in the sashelp.class data set.

37 A sample mail-merge application

38 A sample mail-merge application  The input SAS Server Page: &Name %sysfunc(date(),worddate.) Dear Parents : As &name's teacher I wanted to make you aware of a project we are doing this year. Every month we will be collecting your &age year old &sex's height and weight and recording it. At year end, &name will be asked to produce a chart of their growth over the school year.... The macro variables have the same name, by convention, as the corresponding variables in the data set %sysfunc is used with the date function to produce the text for the date.

39 A sample mail-merge application  The input SAS Server Page:... For your information, here are the measurements that we just collected: Height: &height inches. Weight: &weight pounds. Please don't hesitate to contact me if you have any questions, Regards, &name's teacher

40 A sample mail-merge application  The SAS Program: proc format; /* create a format that maps the value of sex to daughter/son */ value $gender 'F' = 'daughter' 'M' = 'son' ; run;.

41 A sample mail-merge application  The SAS Program: %macro generateDocument; %local numDocuments obsToRead; /* get the number of letters (i.e., observations to use) to generate */ %let numDocuments=0; /* ensure a default value */ proc sql noprint; select count(*) into:numDocuments from sashelp.class; quit;.

42 A sample mail-merge application  The SAS Program: %do obsToRead = 1 %to &numDocuments; data _null_; /* Read the observation and create macro variables for that observation. The vvalue function is used to cause the formatted values to be used. */ set sashelp.class (firstobs=&obsToRead obs=&obsToRead);.

43 A sample mail-merge application  The SAS Program: /* associate the formats with sex and age*/ format sex $gender. age words12.; call symputx('Name',vvalue(Name),'L'); call symputx('Sex',vvalue(Sex),'L'); call symputx('Age',vvalue(Age),'L'); call symputx('Height',vvalue(Height),'L'); call symputx('Weight',vvalue(Weight),'L'); run;.

44 A sample mail-merge application  The SAS Program: filename sspout "&root\output\&Name..html" lrecl = 32767; proc stream outfile=sspout quoting=single; /* use %include for input SAS Server Page */ BEGIN &streamDelim;%include srvrpgs(class.html); ;;;; run; %end; %mend generateDocument; %generateDocument

45 A sample mail-merge application  Alternatives available in my SAS Press e-book and blog:  Generating a Word document (e.g., RTF file) instead of HTML.  Use DOSUBL in the data step to read one observation at a time and generate a letter (instead of macro looping): DOSUB and DOSUBL - Data Driven Development DOSUB and DOSUBL - Data Driven Development

46 Creating a custom (clickable) calendar

47 Creating a custom (clickable) calendar  This example illustrates using resources found on Web.  And the Web, with the help of a Google search, provides a rich source of samples and starting points to create their own SAS Server Pages that can do most anything.  The FullCalendar plugin for JQuery is used. Creating a SAS Server Page to do that is discussed in the blog entry Leveraging JQuery Widgets - An Events Calendar.FullCalendarJQueryLeveraging JQuery Widgets - An Events Calendar  PROC JSON, new in SAS 9.4, is used to produce the JSON input (JavaScript Object Notation) used by the FullCalendar JQuery plugin. JSON

48 Creating a custom (clickable) calendar  The SAS Program: proc stream outfile=sspout quoting=single; /* use %include to define the input SAS Server Page */ BEGIN &streamDelim; %include srvrpgs(blogCalendarProcJson.html); ;;;; run;

49 Creating a custom (clickable) calendar  The events data set:

50 Displaying data graphically - Tag Clouds  Tag clouds are commonly used in blog entries to highlight keywords and other data.  They can also a great way to display BI data  Lets Compare a Tag cloud with a pie chart and a bar chart.  Seems pretty clear that Tag clouds are visually more appealing and easier to read and interpret.

51 Displaying data graphically - Tag Clouds  This example is fully discussed in the following blog entries and those details will not be repeated here:  Tag Cloud SAS Server Page Components - Part 1 Tag Cloud SAS Server Page Components - Part 1  Tag Cloud SAS Server Page Components - Part 2 (of 2) Tag Cloud SAS Server Page Components - Part 2 (of 2)  Tag Clouds vs. Pie vs. Bar Charts Tag Clouds vs. Pie vs. Bar Charts  SAS Server Pages in Batch? Absolutely! SAS Server Pages in Batch? Absolutely!  SAS Server Pages in Batch - Adding a BY variable to the tagCloud macro SAS Server Pages in Batch - Adding a BY variable to the tagCloud macro

52 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 addresses using PROC STREAM and SAS Server Pages in BI environments: PROC STREAM and SAS Server Pages: Generating Custom User Interfaces – 9am Wednesday Chesapeake 7 Theater 42.PROC STREAM and SAS Server Pages: Generating Custom User Interfaces

53 More on PROC STREAM  Also Check Out:  ebook SAS Server Pages: Generating Dynamic Content.SAS Server Pages: Generating Dynamic Content  blog: Jurassic SAS® in the BI/EBI World.Jurassic SAS® in the BI/EBI World  The full text for both of my papers can be found at My Papers and Presentations on sasCommunity.org.My 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.

54 Papers and Presentations on sasCommunity.org