As the first step in the decommissioning of sasCommunity.org the site has been converted to read-only mode.
Here are some tips for How to share your SAS knowledge with your professional network.
Rich Internet Applications Using SAS/IntrNet and Microsoft Silverlight
- 1 Abstract
- 2 Introduction
- 3 Why are RIAs important for SAS developers?
- 4 Silverlight Defined
- 5 Microsoft Components
- 6 SAS Components
- 7 Sample Application
- 8 Conclusion
- 9 References
- 10 Sample Silverlight Sites
- 11 Acknowledgements
- 12 Recommended Reading
- 13 Contact Information
Users were impacted if they upgraded or changed browsers. Behind the scenes, though, Web developers were significantly impacted by confusing coding guidelines as well as having to test continually on multiple browsers and versions. Additionally, the toolsets for developing web applications were hard to use especially for debugging.
Web 2.0 is different. Web 2.0 will have established frameworks for building applications and will use professional development platforms with robust debugging and testing support. A bright area in the Web 2.0 world is the concept of Rich Internet Applications (RIAs): applications that look and feel like a Windows application but are, in fact, hosted on the Web. These new RIAs will have robust graphics, locally cached storage, fast application response time, and the ability to do a lot of tasks locally rather than on a server. This paper will focus on one of the newest technologies to allow for RIAs known as Microsoft Silverlight.
Many SAS Web developers use either SAS/IntrNet or use other technologies such as the SAS 9 Business Intelligence/Enterprise Business Intelligence (BI/EBI) Architecture (that are built on top of SAS Integration Technologies) to expose SAS information to the Web. This paper will demonstrate how to incorporate existing SAS products into an RIA framework. The examples presented here use the SAS/IntrNet Application Dispatcher but could just as easily use the SAS 9 BI/EBI Technologies.
RIAs are a vision for where the Web should be. It is a vision rooted in the idea that modern, object-oriented languages, debuggable code, and rich development libraries should be the developer norm, and that the end-user experience must be in line with a Windows experience. A number of competing frameworks have come onto the market to support modern RIA development. These include Adobe AIR, Microsoft Silverlight, OpenLazlo, and others.
This paper will focus on Silverlight and the use of SAS to generate Silverlight content. This is done merely to focus the paper and provide a starting point. SAS developers should be able to use the same concepts with the other frameworks if they so desire.
Silverlight can be integrated with SAS in a number of ways. Because Silverlight utilizes an XML language for doing the markup, it is easy to generate that XML using SAS. This provides a bridge for existing SAS developers and opens the door to do more robust work once they familiarize themselves with the basics of the markup language and the deployment process.
Why are RIAs important for SAS developers?
Aids in understanding information
RIAs are important because they deliver information more interactively. That means faster decision making. The ability to display information to a user and allow for rich interaction means that business information is easier to consume, and that leads to better business intelligence. Advanced graphical capabilities allow for new, creative means of exploring data.
Easier to maintain
RIAs are easier to maintain since browser and operating system support is baked in, and the developer does not have to worry about how the information is rendered on various platforms.
Helps you to keep up with the times.
RIAs are here. Users are experiencing these changes while they surf, and that means a trickle-down effect at the business level. The more users see these types of rich applications elsewhere, the more they will want the corporate IT departments to support rich functionality.
What are Silverlight’s strengths?
- Silverlight is cross-platform and runs on Linux, Windows, and Macs.
- It is cross-browser and runs on Internet Explorer, Opera, Safari, Firefox, and others.
- Silverlight is a safe choice for Web developers since it runs on the vast majority of platform/browser combinations available today.
- Silverlight applications can also be coded in a variety of languages such as C#, VB.NET, Ruby, Python, C++, and many others.
- Microsoft is also releasing a Dynamic Language Runtime (DLR) that will allow for backend code to be dynamically compiled. This is important because the code that drives events on the Website can be generated by SAS. Dynamic code can be generated by any language and will automatically be compiled as needed. This will allow for fast code execution rather than having to parse the code each time it is called.
- Silverlight applications can be converted into Windows applications and vice-versa 
- Silverlight is free and Microsoft provides developer tools to simplify the creation of Silverlight applications. These tools include Microsoft® Expression Blend and Microsoft® Visual Studio 2008.
- There is a large base of 3rd party tools that greatly simplify development.
A Silverlight application consists of 2 types of files: code-behind and Extensible Application Markup Language( XAML). Code-behind handles the logic and event execution side and XAML handles the layout and presentation side.
When creating a Silverlight application, it is important to keep the following in mind:
- If the goal is to only present data, only the XAML is required.
- If interaction with the page is required, the code-behind files need to be generated.
Microsoft offers tools to help create the XAML and the code-behind, although both can be coded using a text editor. These tools are Microsoft Expression Blend for creating the XAML and graphical layout and Microsoft Visual Studio for creating the code-behind. These tools greatly simplify the creation of the application, and work hand-in-hand with each other. Editing files in one tool will automatically reflect in the other tool. Once a generalized XAML layout is established, SAS can be used to customize that markup code to make it more dynamic.
What does this mean though? XAML lays out how a page looks and handles some behaviors such as animation. Code-behind is processing logic that handles events such as the page load, a button click, a treeview select, and other events. Code-behind is also used for business logic processing such as delivering database content to the screen.
Code-behind can be written in any .NET language including C#, VB.NET, C++, and others.
XAML is what is used in Silverlight to display a page. Think of it as similar to HTML but much more powerful. XAML was developed by Microsoft as a way to describe graphical elements and their actions. XAML is a common mark-up language that can be used by Windows applications, Web sites, mobile applications, and console applications. This ubiquity of a markup language means that a simple application should run, as-is, across multiple platforms. It also reduces the amount of knowledge a programmer must have when porting from one platform to another.
Here is some example XAML code that displays “Hello World” in a textbox:
<Canvas xmlns="http://schemas.microsoft.com/client/2007" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Loaded="Page_Loaded" x:Name="parentCanvas" Loaded="Page_Loaded" x:Class="HelloWorld.Page;assembly=ClientBin/Demo1.dll" Width="640" Height="480" Background="White" > <TextBlock Width=”202” Height=”25” Canvas.Left=”70” Canvas.Top=”74” Text=”Hello World” TextWrapping=”Wrap” />
Most Silverlight controls do not have express tags such as 'Text' but instead have tags such as 'Content'. Hence, a developer can embed almost any 'Content' into a given control. Perhaps a video on a button or an Image next to a RadioButton. Most developers should build common controls as UserControls so that they can be reused. For a SAS programmer, once they have a basic Canvas laid out, perhaps a TreeView that gets the datasets available in a library, they can just reuse this Canvas as needed from one project to the next.
One other point: XAML is merely text. It cna be generated by SAS directly and incoporated into a batch job step. The decision for a SAS programmer is whether to use SAS as merely a data provider or to use SAS as a code generator. Either option can work.
There are a number of tools made by Microsoft to cimplify working with XAML and Silverlight. These include:
- Microsoft Visual Studios (some versions are free). This is normally used to create the code-behind.
- Microsoft Expression Blend. This is normally used to create the design.
There are a number of SAS tools and technologies that can be used to generate XAML, e.g.,
- ODS templates and tagsets created using the TEMPLATE procedure
- DATA step using PUT statements
- SAS Server Pages as described in the SAS Press book "Building Web Applications with SAS/IntrNet®: A Guide to the Application Dispatcher" 
Since RIAs are, by definition, Web applications, it is important that the generation of the XAML content be handled via a Web interface such as:
- The SAS/IntrNet Application Dispatcher
- htmSQL (part of the SAS/IntrNet product)
- The SAS 9 Stored Process Server (part of the SAS Integration Technologies product)
- A Web Service that packages any of the above under the covers.
For simplicity, the rest of this paper refers to SAS/IntrNet or the SAS/IntrNet Application Dispatcher. However any of the four options listed above can be used. The choice as to which is the most appropriate will depend on the application and the environment.
Since XAML is simply XML text, it is easy to use SAS to generate the text. In fact, SAS can be used to generate not just Silverlight applications but any application that can interpret XAML. For example, Windows applications can now be created using XAML and so can a number of other applications including mobile applications.
For Silverlight, the natural choice within SAS for rendering the mark-up can be the SAS/IntrNet Application Dispatcher. Simply put, instead of using SAS/IntrNet to render HTML, use it to render XAML. Here is a high-level illustration of the overall process:
Figure 1 High-Level Overview of Silverlight to SAS Process
When a user calls a SAS/IntrNet application, a SAS program is executed that renders the Silverlight page. That page is delivered to the user’s browser where the Silverlight engine interprets the XAML and displays the content to the user. After a user makes any edits or changes, the information can again be passed to a SAS/IntrNet application where the information can then be acted upon.
How to create a Silverlight-Enabled application using SAS
The basic process flow can be summarized in the following steps:
- Design a Silverlight application using Microsoft Expression Blend or Microsoft Visual Studio (or both).
- Use the XAML code produced by the above as a guide to determine what XMAL the SAS program(s) needs to generate. By simply examining the XAML code produced by the editors, SAS programmers can replicate that code inside of their SAS programs to implement the same functionality dynamically using SAS data
- Code-behind should be created using Microsoft Visual Studio 2008, which works hand-in-hand with Expression Blend.
The SAS process that creates the XAML needed by the Silverlight application may be invoked using any of the products/architectures discussed above (e.g., the SAS/IntrNet Application Dispatcher, htmSQL, the SAS 9 Stored Process Server, a Web Service)
To demonstrate the power of this technology a sampleis shown.
Note: You will need to install the Silverlight plugin to see the application.
The entire Silverlight project can be found here: SGF2008 Demo project. This project requires Visual Studios 2008. An express edition is available free of charge from Microsoft.
Consider a business application for the medical community, specifically an endocrinology practice that specializes in patients with Diabetes who are on an insulin pump. Patients are able to upload data from their pumps to a web site where a Doctor or Certifed Diabetes Educator is able to review the data and record notes about the data - in this case a video recording.
The sample application presented here is clearly fictitous and is intended to demonstrate how Silverlight and SAS can be combined to present information (i.e., the video) and data (graphical displays of Blood Sugar readings, carbohydrates consumed and insulin delivered).
The screenshot below (to be added later) shows the initial welcome page. The applications displays the following data items, all of which are obtained by submitting a querying to SAS (either the SAS/IntrNet Application Dispatcher or the SAS 9 Stored Process Server):
- the list of patients is listed the left hand side of the display
- for each patient, a variety of demographic fields, e.g.,
- Diagnosis Date
- Last HbA1C test
- Date of the thier HbA1C
- Location of the video file for their current status
- and so on
as popularized by Edward Tufte that display the data from the patients insulin pump for
- Blood Sugar (as measured by their meter)
- Carbohydrates consumed
- Insulin Dose
The data needed by the applcation are returned by two SAS programs:
- Returns all the demographic information needed to populate the patient list as well as the patient demographics information on each panel.
- Returns the X-Y pairs for the sparklines.
SAS Program to return the Patient Information Data
The following program can be run by either the SAS/IntrNet Application Dispatcher or the SAS 9 Stored Process Server and returns the entire data set to the Silverlight application as an XML file. The Silverlight application calls the program via an asynchronous call (so that the interface is never left hanging waiting for a return). When the XML is received, the Silverlight program uses LINQ to XML to query the information and populate the controls.
libname _webout xml; data _webout.patients; set slvrlght.patients; run;
The libname statement associates the XML engine with the _webout fileref that is used to streams the data back to the calling program (in this case the Silverlight application). The code shown above uses the default SAS XML format for data to return the XML data to the Silverlight application. The Silverlight application can then bind the returned XML data to the applications fields as needed.
The XML data stream returned by the above program is shown below.
insert the xml here
SAS Programs for the Sparkline Data
Overview of the three techniques and the needed XAML
Using SAS Server Pages
Using a DATA step with PUT/FILE statements
Combining SAS Server Pages with the PUT/FILE technique
RIAs open up the possibility for really rich applications on the Web. These rich applications can open up the business intelligence possibilities by creating very attractive graphical environments. SAS Web developers should consider deploying new RIAs within their environment. These RIAs tend to be easier to code against, easier to maintain, and offer users a much better mechanism for interactivity.
Silverlight is a good choice for SAS developers to get started with. With its use of XAML as the primary display methodology, SAS programs can create the necessary files to build advanced Silverlight applications while allowing SAS programmers to leverage their existing knowledge.
- .NET is Microsoft’s generalized programming framework. Almost all Microsoft development is done in .NET from Windows to Web to mobile applications. .NET supports numerous programming languages including C#, VB.NET, C++, Perl, Python, Ruby, and others.
- Silverlight uses a subset of Windows Presentation Foundation (WPF) which is the new method for building Windows applications. Some WPF functionality is not available in Silverlight so not all code can be ported from a Windows application to a Web application.
- InfoWorld, Microsoft Silverlight rivals Flash, AJAX, Oct 1, 2007.
- Henderson, Don. Building Web Applications with SAS/IntrNet®: A Guide to the Application Dispatcher. 1.0. Cary: SAS, 2007.
Sample Silverlight Sites
Almost all Silverlight sites to date have been referenced here:
- Spinning TextBox
- Weaatherbug Mobile App
- Jelly Graphs
- HardRock DeepZoom
- Financial Page
- Demo Page for SGF 2008
Thanks to Vince DelGobbo of SAS for the encouragement and advice and Mike Wolf and Dave Wolf of Cynergy Systems for the inspiration.
Your comments and questions are valued and encouraged. Contact the author at:
SAS Institute, Inc. product or service names are registered trademarks or trademarks of SAS Institute, Inc. in the USA and other countries. ® indicates USA registration.
Other brand and product names are trademarks of their respective companies.