INTEGRATE SAS REPORTS WITH GOOGLE MAPS Vineet Kaul
Business Case – Use Of Mashups. <ul><li>Mashups create new services for consumers which allow them to further create a lots of new possibilities and increase the level of personalization of the Internet. </li></ul><ul><li>Information overload is a problem that many companies face, whether it’s within the company itself or when presenting information to users. Mashups can help overcome this problem by allowing one company to display concise information derived from a wide variety of sources. </li></ul><ul><li>Mashups are a form of integration technology as they can be adapted to join together many technologies and use many types of implementation languages. Mash-ups can take advantage of services such as Google Maps, Ajax, warehouse database, and an information processing analytics server to provide a powerful UI tool. Being able to leverage distributed environment, mashup applications can benefit from consolidated processing speed from various server it accesses for data. </li></ul><ul><li>For our case, we are looking at scenario where user maintains a intranet dashboard application. Current requirement is to provide a Google Maps mashup with revenue and location details of various stores for departmental store chain. User can select the departmental store from the UI and application will render the details for the selection mashed up with maps. The location and revenue information is available on SAS BI server that connects to a warehouse database. The revenue information is rolled up from warehouse fact and dimension tables by SAS code provided as XML stream through a URL. Important point here is that SAS information is provided by a marketing vendor and hosted on URL outside the organization hosting the web application. </li></ul>
Dashboard - UI. View of United States showing commercial stores for Kroger Holdings, Inc. Options to select organizations for which revenue details are to be viewed. Click on “Dashboard” button displays result on map for selected organization Each overlay icon represents store location.
Click on each overlay icon would display an info message window with revenue details and the location of the store. Dashboard - UI.
<ul><li>All the locations that cannot be located on the map are listed below by the program. It’s strange looking at this example why map cannot locate places like Georgia and New York. There were two reasons why I did not debug this issue . </li></ul><ul><li>It was a typical GMap problem and not really related to integration. As I had very limited time to complete this POC, I’d pass this on to more seasoned web developers who’d be reading this. </li></ul><ul><li>The issue tested my error handling. Under certain cases, there would be locations for which Google map fails to co ordinates E.g. Karuvadikuppam, India. (No, this is not a fictional name. You’d find it in Union Terr. Of Pondicherry, India). </li></ul>Dashboard - UI.
Design. All modern web browsers impose a security restriction on network connections, which includes calls to XMLHttpRequest. This restriction prevents a script or application from making a connection to any web server other than the one the web page originally came from. This would prevent you from accessing data on the SAS server from your web application hosted on your domain (E.g. http://www.myserver.com) Instead of making your XMLHttpRequest calls directly to the web service, you make your calls to your web server proxy. The proxy then passes the call onto the web service and in return passes the data back to your client application. Because the connection is made to your server, and the data comes back from your server, the browser has nothing to complain about. In our case, proxy would be a perl script hosted on our web server. End user for our web application would invoke the perl script using Ajax. The script further accesses the SAS report on the SAS BI server and gets the XML output from the SAS report and passes it onto Ajax handler. SAS BI Server SAS BI server hosts stored process programs. SP render report data in XML stream that is used as input to Google map. Web application hosted on web server has dashboard pages. Dashboard displays Google maps with option to get data for various organizations. When user sends request, data for selected organization is accessed from SAS server and overlayed on map as icons. Requests are sent as Ajax XMLHttpRequest object. Ajax objects pings a proxy perl script which in turn invokes stored process on SAS BI server. Stored process responds by providing an XML data stream. The data stream is passed by perl script to the Ajax object. An XML parser handles the Ajax response and feeds Google map object which renders the map on the dashboard with SAS data mashed up with the map.
This is what the data looks like in SAS E Guide. The POC is implemented with two vendors – Kroger Holdings, Inc. and Safeway, inc. The SAS code calculates revenue for each of these vendor grouped by State. Revenue figures are arbitrary and could be any meaningful calculation. Our objective is to get the data from SAS E Guide report and mash it up with Google map to provide a powerful dashboard environment. This would leverage high end number crunching capability of SAS Analytics server with real-time maps. Other than using Google maps, similar technique could be used to leverage other web APIs like Google graphs, Google Visualization APIs etc. Data transfer is done using XML. So, any API or Web Service that can take XML data could be used to make distributed system that gives best of each individual component. SAS data – Report Structure.
This is how the data looks like in XML format. This format is the key to transfer data between various services over the NET. SAS data – XML Structure.
Create a Stored Process in SAS. A stored process is a SAS program that is stored on a server and can be executed as required by requesting applications. You can use stored processes for Web reporting, analytics, building Web applications, delivering packages to clients or to the middle tier, and publishing results to channels or repositories. Stored processes can also access any SAS data source or external file and create new data sets, files, or other data targets supported by SAS. Create stored process – General Information.
Refer to AOLDW library. Library accesses AOLDW schema on Oracle server. AOLDW schema is warehouse having vendor information. Select data from table and limit query on Vendor. This gives us flexibility to get data for vendor selected by user Transfer the data selected by query to _WEBOUT library. This would convert SAS dataset to XML data stream. The LIBNAME statement defines the output for the stored process as streaming output, or _WEBOUT. Uncheck the box for "Stored process macros". Refer SAS Usage Note 13599. Create stored process – SAS Code.
Provide the location of stored process on SAS Metadata server. This path would be referred when calling the report from URL. Create stored process – Metadata Location.
Set the execution server as Logical Stored Process Server. Create stored process – Execution Environment.
Define parameters for the stored process. We have defined parameter Vendor to dynamically get data for different vendors/organization based on user input. Create stored process - Parameters.
Select the Output Options to Streaming Output as we want to pass xml stream to Google maps. Create stored process – Output/Input.
The Crypt::SSLeay package provides Net::SSL, which is loaded by LWP::Protocol::https for https requests and provides the necessary SSL glue. WWW::Mechanize, or Mech for short, helps you automate interaction with a website. It supports performing a sequence of page fetches including following links and submitting forms. CGI routines for writing to the HTTPD (or other) error log. Print XML output from SAS program back to calling browser. Provide the url to the Perl script. This would be the location of stored process on SAS Metadata Server. Observer that url has parameter “Vendor” attached to it after “&”. This provides the organization to stored process for which data is to be accessed. Provide SAS credentials and url to the Mech object. Mech object gets the output contents to the $page variable. Get contents back from the url using the Mech object. Proxy script design.
Explaining AJAX code – Send request to proxy. The XMLHttpRequest object implements an interface exposed by a scripting engine that allows scripts to perform HTTP client functionality, such as submitting form data or loading data from a server. The XMLHttpRequest Object sends request to the proxy perl scrip on the server. Callback method assigned via this attribute. processChange() function is assigned to process response from XMLHttpRequest object.
Removes all overlay from the map. The old overlays are to be removed every time a new organization is loaded. The response from the proxy script is returned in responseText object. Use Microsoft XMLDOM to parse the XML data. Loop through the XML data and call showAddress() function. The function implements overlays on the map for each location and assigns Click() event to each overlay item to show revenue details when user click on it. The showAddress() is explained in detail in later slides. Explaining AJAX code – Handle response from proxy.
We create an icon using the G_DEFAULT_ICON type You can access the Google Maps API geocoder via the GClientGeocoder object. Use GClientGeocoder.getLatLng() to convert a string address into a GLatLng. This method takes as parameters a string address to convert, and a callback function to execute upon retrieval of the address. The markers parameter defines a set of one or more markers to attach to the map image. A GMarker marks a position on the map. It implements the GOverlay interface and thus is added to the map using the GMap2.addOverlay() method. A marker object has a latlng, which is the geographical position where the marker is anchored on the map, and an icon. Registers an event handler for a custom event on the source object. Click() even has been added to display revenue and address when user clicks on the icon. Explaining AJAX code – Add overlays to map.
Confessions …... <ul><li>This might not be the best way to integrate SAS with Google maps. This approach is developed out of thought on how to get different systems talk rather than finding out ways on google search. Under the circumstances, the results were encouraging enough to have me document and present it for peer review. </li></ul><ul><li>There are many gaps in the armor. Some, which I observed, are given below while others could be caught by readers of this article. The purpose of this article is to demonstrate a proof of concept rather than make a working application. </li></ul><ul><ul><li>The XML response from SAS report is handled using responseText property of XMLHttpRequest rather than responseXML property. Ideally, responseXML should be used for handling XML data. </li></ul></ul><ul><ul><li>The text from responseText property is parsed using Microsoft XMLDOM. This would be a limitation when working with non Microsoft browsers. However, users of such browsers need not despair as they just have to look around web to get a native XML parser. </li></ul></ul><ul><ul><li>The code for displaying information on map is not be optimised. E.g. GeoCode information for each location can be cached to make response time faster and improve end user experience. There is much that could be done in current code to improve such efficiencies. </li></ul></ul><ul><li>I am not sure I did a great job in documenting the code. I’ll take comfort in the fact that documentation is not forte of good developers. To make up for this, I’d be happy to answer questions that readers might have (to the best of my ability !!!!). In addition to questions, feedback would be much appreciated. </li></ul>