Integrate SAS With Google Maps

Embed Size (px)

Citation preview

  • 8/12/2019 Integrate SAS With Google Maps

    1/22

    Vineet Kaul

    INTEGRATE SAS REPORTS WITHGOOGLE MAPS

    Vineet Kaul

  • 8/12/2019 Integrate SAS With Google Maps

    2/22

    Vineet Kaul

    Business Case Use Of Mashups.

    1. Mashups create new services for consumers which allow them to further create a lots ofnew possibilities and increase the level of personalization of the Internet.

    2. Information overload is a problem that many companies face, whether its within thecompany itself or when presenting information to users. Mashups can help overcomethis problem by allowing one company to display concise information derived from awide variety of sources.

    3. Mashups are a form of integration technologyas they can be adapted to join togethermany technologies and use many types of implementation languages. Mash-ups cantake advantage of services such as Google Maps, Ajax, warehouse database, and aninformation processing analytics server to provide a powerful UI tool. Being able toleverage distributed environment, mashup applications can benefit from consolidatedprocessing speed from various server it accesses for data.

    4. For our case, we are looking at scenario where user maintains a intranet dashboardapplication. Current requirement is to provide a Google Maps mashup with revenue andlocation 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 selectionmashed up with maps. The location and revenue information is available on SAS BIserver that connects to a warehouse database. The revenue information is rolled upfrom warehouse fact and dimension tables by SAS code provided as XML stream througha URL. Important point here is that SAS information is provided by a marketing vendorand hosted on URL outside the organization hosting the web application.

  • 8/12/2019 Integrate SAS With Google Maps

    3/22

    Vineet Kaul

    View of United States showing commercial stores for Kroger Holdings, Inc.

    Options to select organizations for which revenue details are to be viewed. Click onDashboard button displays result on map for selected organization

    Each overlay icon represents store location.

    Dashboard - UI.

  • 8/12/2019 Integrate SAS With Google Maps

    4/22

    Vineet Kaul

    Click on each overlay icon would display an info messagewindow with revenue details and the location of the store.

    Dashboard - UI.

  • 8/12/2019 Integrate SAS With Google Maps

    5/22

    Vineet Kaul

    All the locations that cannot be located on the map are listed below by theprogram. Its 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.

    1. It was a typical GMap problem and not really related to integration. As Ihad very limited time to complete this POC, Id pass this on to moreseasoned web developers whod be reading this.

    2. The issue tested my error handling. Under certain cases, there would belocations for which Google map fails to co ordinates E.g. Karuvadikuppam,India. (No, this is not a fictional name. Youd find it in Union Terr. OfPondicherry, India).

    Dashboard - UI.

  • 8/12/2019 Integrate SAS With Google Maps

    6/22

    Vineet Kaul

    Design.

    All modern web browsers impose asecurity restriction on networkconnections, which includes calls toXMLHttpRequest. This restriction preventsa script or application from making aconnection to any web server other thanthe one the web page originally camefrom. This would prevent you fromaccessing data on the SAS server fromyour web application hosted on your

    domain (E.g. http://www.myserver.com)

    Instead of making your XMLHttpRequestcalls directly to the web service, youmake your calls to your web serverproxy. The proxy then passes the callonto the web service and in returnpasses the data back to your clientapplication. Because the connection ismade to your server, and the datacomes back from your server, thebrowser has nothing to complain about.

    In our case, proxy would be a perl scripthosted on our web server. End user for ourweb application would invoke the perlscript using Ajax. The script furtheraccesses the SAS report on the SAS BIserver and gets the XML output from theSAS report and passes it onto Ajaxhandler.

    SAS BIServer

    SAS BI server

    hosts storedprocessprograms. SPrender reportdata in XMLstream that isused as input toGoogle map.

    Web application hosted

    on web server hasdashboard pages.Dashboard displaysGoogle maps with optionto get data for variousorganizations. When usersends request, data forselected organization isaccessed from SASserver and overlayed onmap as icons.

    Requests are sent as Ajax XMLHttpRequestobject. Ajax objects pings a proxy perlscript which in turn invokes stored processon SAS BI server. Stored process respondsby providing an XML data stream. The datastream is passed by perl script to the Ajaxobject. An XML parser handles the Ajaxresponse and feeds Google map objectwhich renders the map on the dashboardwith SAS data mashed up with the map.

  • 8/12/2019 Integrate SAS With Google Maps

    7/22

    Vineet Kaul

    This is what the data looks like in SAS E

    Guide. The POC is implemented with twovendors Kroger Holdings, Inc. andSafeway, inc. The SAS code calculatesrevenue for each of these vendor groupedby State. Revenue figures are arbitrary andcould be any meaningful calculation.

    Our objective is to get the data from SAS EGuide report and mash it up with Googlemap to provide a powerful dashboardenvironment.

    This would leverage high end numbercrunching capability of SAS Analytics serverwith real-time maps.

    Other than using Google maps, similartechnique could be used to leverage otherweb APIs like Google graphs, GoogleVisualization APIs etc.

    Data transfer is done using XML. So, anyAPI or Web Service that can take XML datacould be used to make distributed system

    that gives best of each individualcomponent.

    SAS data Report Structure.

  • 8/12/2019 Integrate SAS With Google Maps

    8/22Vineet Kaul

    This is how the data lookslike in XML format. Thisformat is the key to transferdata between variousservices over the NET.

    SAS data XML Structure.

  • 8/12/2019 Integrate SAS With Google Maps

    9/22Vineet Kaul

    Create a Stored Process in SAS. A stored process is a SAS programthat is stored on a server and can be executed as required byrequesting applications. You can use stored processes for Webreporting, analytics, building Web applications, deliveringpackages to clients or to the middle tier, and publishing results tochannels or repositories. Stored processes can also access anySAS data source or external file and create new data sets, files, orother data targets supported by SAS.

    Create stored process General Information.

  • 8/12/2019 Integrate SAS With Google Maps

    10/22Vineet Kaul

    Refer to AOLDW library.

    Library accesses AOLDWschema on Oracle server.

    AOLDW schema iswarehouse having vendorinformation. Select data from table and

    limit query on Vendor.This gives us flexibility toget data for vendorselected by user

    Transfer the data selected by query to_WEBOUT library. This would convertSAS dataset to XML data stream.The LIBNAME statement

    defines the output forthe stored process asstreaming output, or

    _WEBOUT.

    Uncheck the box for"Stored process macros".Refer SAS Usage Note13599.

    Create stored process SAS Code.

  • 8/12/2019 Integrate SAS With Google Maps

    11/22Vineet Kaul

    Provide the location of stored process onSAS Metadata server. This path would bereferred when calling the report fromURL.

    Create stored process Metadata Location.

  • 8/12/2019 Integrate SAS With Google Maps

    12/22Vineet Kaul

    Set the execution server as LogicalStored Process Server.

    Create stored process Execution Environment.

  • 8/12/2019 Integrate SAS With Google Maps

    13/22Vineet Kaul

    Define parameters for the stored process.We have defined parameter Vendor todynamically get data for differentvendors/organization based on userinput.

    Create stored process - Parameters.

  • 8/12/2019 Integrate SAS With Google Maps

    14/22Vineet Kaul

    Select the Output Options to StreamingOutput as we want to pass xml stream toGoogle maps.

    Create stored process Output/Input.

  • 8/12/2019 Integrate SAS With Google Maps

    15/22Vineet Kaul

    Create stored process - Summary.

  • 8/12/2019 Integrate SAS With Google Maps

    16/22Vineet Kaul

    The Crypt::SSLeay package provides Net::SSL, which is loaded byLWP::Protocol::https for https requests and provides the necessary SSL glue.

    WWW::Mechanize, or Mech for short, helps you automate interaction with awebsite. It supports performing a sequence of page fetches including followinglinks and submitting forms.

    CGI routines for writing to the HTTPD (or other) error log.

    Print XML output from SAS program back to callingbrowser.

    Provide the url to the Perl script. This would be the locationof stored process on SAS Metadata Server. Observer thaturl has parameter Vendor attached to it after &. Thisprovides the organization to stored process for which datais to be accessed.

    Provide SAS credentials and url to the Mechobject. Mech object gets the output contents tothe $page variable.

    Get contents back from the url using the Mech object.

    Proxy script design.

  • 8/12/2019 Integrate SAS With Google Maps

    17/22Vineet Kaul

    Explaining AJAX code Create Map.

    Once we've created a map via the GMap2 constructor, we need to initialize it. Thisinitialization is accomplished with use of the map's setCenter() method. ThesetCenter() method requires a GLatLng coordinate and a zoom level and thismethod must be sent before any other operations are performed on the map,including setting any other attributes of the map itself.

    When you create a new map instance, you specify aDOM node in the page (usually a div element) as acontainer for the map. We obtain a reference to thiselement via the document.getElementById()method. In this example, SASReport is the Id of

    the div element on the page.

    GMap2 - the Elementary Object

    URL points to the location of the JavaScript file that includes allof the symbols and definitions you need for using the GoogleMaps API. Your page must contain a script tag pointing to thisURL, using the key you received when you signed up for the API.

  • 8/12/2019 Integrate SAS With Google Maps

    18/22Vineet Kaul

    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 assubmitting form data or loading data from a server.

    The XMLHttpRequestObject sends request to the proxy perlscrip on the server.

    Callback method assigned via this attribute. processChange()function is assigned to process response fromXMLHttpRequest object.

  • 8/12/2019 Integrate SAS With Google Maps

    19/22Vineet Kaul

    Removes all overlay from the map.The old overlays are to be removedevery time a new organization isloaded.

    The response from the proxy script isreturned in responseText object. UseMicrosoft XMLDOM to parse the XMLdata. Loop through the XML data andcall showAddress() function. Thefunction implements overlays on themap for each location and assignsClick() event to each overlay item toshow revenue details when user clickon it. The showAddress() is explainedin detail in later slides.

    Explaining AJAX code Handle response from proxy.

  • 8/12/2019 Integrate SAS With Google Maps

    20/22Vineet Kaul

    We create an icon using the G_DEFAULT_ICONtype

    You can access the Google Maps API geocoder via the GClientGeocoderobject. Use GClientGeocoder.getLatLng() to convert a string addressinto a GLatLng. This method takes as parameters a string address toconvert, and a callback function to execute upon retrieval of theaddress.

    The markers parameter defines a setof one or more markers to attach tothe 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 geographicalposition where the marker is anchored on the map, and an icon.

    Registers an event handlerfor a custom event on thesource object. Click() evenhas been added to displayrevenue and address whenuser clicks on the icon.

    Explaining AJAX code Add overlays to map.

  • 8/12/2019 Integrate SAS With Google Maps

    21/22Vineet Kaul

    Confessions ...

    1. 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 outways on google search. Under the circumstances, the results were encouraging enoughto have me document and present it for peer review.

    2. There are many gaps in the armor. Some, which I observed, are given below whileothers could be caught by readers of this article. The purpose of this article is todemonstrate a proof of concept rather than make a working application.

    1. The XML response from SAS report is handled using responseText property ofXMLHttpRequest rather than responseXML property. Ideally, responseXML should be used forhandling XML data.

    2. The text from responseText property is parsed using Microsoft XMLDOM. This would be alimitation when working with non Microsoft browsers. However, users of such browsers neednot despair as they just have to look around web to get a native XML parser.

    3. The code for displaying information on map is not be optimised. E.g. GeoCode informationfor each location can be cached to make response time faster and improve end userexperience. There is much that could be done in current code to improve such efficiencies.

    3. I am not sure I did a great job in documenting the code. Ill take comfort in the fact thatdocumentation is not forte of good developers. To make up for this, Id be happy toanswer questions that readers might have (to the best of my ability !!!!). In addition toquestions, feedback would be much appreciated.

  • 8/12/2019 Integrate SAS With Google Maps

    22/22

    Thank You

    Vineet [email protected]