Live Google maps in SAS -- multiple markers

In my prior post, Spice up SAS output with live Google maps, I discussed the idea of delivering live Google map through SAS output and demonstrated the feasibility of doing so in SAS Information Delivery portal. Similarly, it can be done for any SAS HTML output.  You would just need to replace file _webout for SAS portal with any file reference pointing to an HTML file.

Since the first post was well received by the SAS community and generated numerous questions, I have decided to expand on it and show some additional functionality that can be incorporated into SAS output in regards to the Google maps.

In this post, I will demonstrate how to use SAS to generate Google map with multiple points (or markers, using Google terminology) and incorporate it into SAS HTML output.

Using SAS data sets as input 

In the first post I used SAS macro variables to pass the data into SAS-generated Javascript that embeds Google map into SAS output. It was adequate for proving the concept; however, here I will use SAS dataset as a natural source of the data.

Let’s assume that we have the following data table with three observations, each corresponding to a single point on the Google map:

Figure 1. SAS data set with variables for three location markers.

Figure 1. SAS data set with variables for three location markers.

Figure 2. Information displayed with each marker.

Figure 2. Information displayed with each marker.

Although for showing three points on map as markers, we only need the latitude and longitude (lat and lng variables in our table), the remaining variables will be used to display an information window when user clicks on a marker, as shown in Figure 2:

Writing the code 

Displaying multiple live Google map markers in your SAS output can be accomplished in six fairly easy steps.  You can view and download the full sample SAS code.  Here are explanations and clarifications for each section in this example:

1. Specify the HTML output file location.  Use the FILENAME statement to assign a fileref to the physical location of the HTML file you are going to generate.

2. Prepare the data. To make this example more self-contained, I generate the SAS table in Figure 1 within the code itself.  In reality, you would prepare your data table by pulling or combining data from a database or other data storage.

3. Determine the map center. For a single marker implementation, a trivial solution would be to assign map center to the same location as the marker.  When there are multiple markers, some map center considerations have to be made. In the latter case, you would want Google map center to be somewhere between the multiple markers. A geometrical way of handling this problem is to let the midpoint of the latitude and longitude range determine the center coordinates. Here is the formula to calculate the center coordinates:

C(lat, lng) = ( [max(lat) – min(lat)]/2,  [max(lng) – min(lng)]/2 )

In this implementation, I chose a less geometrical, but a simpler and viable approach using averages and used the MEANS procedure in the sample code to implement it:
C(lat, lng) = ( avg(lat),  avg(lng) )

4. Initialize the map. This code portion uses a DATA _NULL_ step to generate a non-repeatable section of the code, and it mostly coincides with the code from a previous post with an exception.  In this example, I use the map center coordinate variables that were calculated in the previous step instead of macro variables. To simplify, I also use a constant zoom level (zoom: 12) to control the Google map scale. Obviously, if needed, you can determine the scale dynamically based on your data.

5. Add multiple markers. This portion of the code also uses a DATA _NULL_ step, but here the DATA step loops through the source data as many times as there are observations in the source data, thus generating as many markers. Here are other notes about this section:

  • To append to the output HTML files, I use the mod option:
    file fout mod;
  • I use inline styling to modify the default width of the Google map information window. Similarly, you may apply other CSS styles here or in an external CSS using class= or id= selectors.
    <div style="width:150px;">
  • I use the following statement to generate the Javascript variable suffix corresponding to each observation in the source SAS data set:
     i = strip(_n_);

6. Wrap up the HTML file. Again, I use a single-iteration DATA _NULL_ step to wrap up the Javascript and HTML. The bottom portion of the code contains information about the styling of the final embedded Google map:

<div id="map-canvas" style="width:550px; height:350px; border: 2px solid #3872ac;"></div>

Using the final map
Running the above code sample produces the gmapoutput_mm.html file which, when opened in a web browser, produces the following Google map containing all three points of interest represented by markers shown in Figure 3.

Figure 3. Final map showing  three location markers and an information block generated by data in a SAS data set.

Figure 3. Final Google map showing three location markers and an information window.

Click for an interactive version of the map.

This map is interactive: you can move it around, zoom in and zoom out, and you can click on markers to display detail information about that location in a popped information window.

The code that produced this map is completely data-driven in the sense that all the information comes from a data table. I'm hoping that, by now, you can see how relatively easy it is to incorporate Google maps into SAS-generated output and that you will start using this technique for your benefit.

Post a Comment

SAS Global Forum 2015: Your presentation is needed!

Do you know something about SAS® software that other SAS users would love to learn?

Of course you do!

Whether you’re a student or a member of the Circle of Excellence, every SAS programming project, every analysis or forecasting model is an opportunity to gain new insights into SAS processing or to develop new techniques.

No matter how you measure your SAS experience—what you’ve learned is valuable to other SAS users. So, start typing up your ideas. The SAS Global Forum 2015 call for content opens today! Read More »

Post a Comment

WUSS 2014—same event, new look and feel!

WUSS 2014 logo Do you know the way to San Jose? By now, SAS users are getting to know the way to the Western Users of SAS Software’s (WUSS) annual event on September 3-5, 2014.

Although this is the third time WUSS has been held in San Jose at The Fairmont Hotel, this year’s event will introduce a lot of changes, one of which includes the name of the event—going forward, the WUSS Conference will be called the WUSS Educational Forum and Conference. The purpose of the name change is to emphasize all of the learning opportunities there are at WUSS. Besides the name change, WUSS has more exciting changes to announce: Read More »

Post a Comment

One grid to rule them all – tuning your environment for SAS Enterprise Guide

Most organizations enjoy a plethora of SAS user types—batch programmers and interactive users, power users and casual—and all variations in between. Each type of SAS user has its own needs and expectations, and it’s important that your SAS Grid Manager environment meets all their needs.

One common solution to this dilemma is to set up separate configurations based on a mix of requirements for departments, client applications and user roles. The grid options set feature in SAS 9.4 makes this task much easier. A grid options set is a convenient way to name a collection of SAS system options, grid options and required grid resources that are stored in metadata. Read More »

Post a Comment

Old PROC REPORT code? Let's clean it up!

Did you inherit code that was written eons ago?  Do you find old programs to copy the PROC REPORT code and then simply change the variable names for your new program?  Have you wondered what all of those options do?  Do you ever send output to the Listing destination (the Output Window) anymore?

If you said yes to any of the questions above -- clean it up!  PROC REPORT has been around forever, but it has changed and evolved over the years to facilitate the creation of nicer looking output, specifically in non-Listing ODS destinations. Read More »

Post a Comment

Setting up SAS Business Intelligence environments – the right way

When new SAS users get introduced to the SAS Business Intelligence software (SAS BI), along with the thrill of a wide spectrum of new and desirable functionality, almost always comes a state of confusion--if not panic.

How do we go about adapting it to our organization IT guidelines? How do we arrange and support development and production environments? How do we set up our SAS developers so they can collaborate, but not overwrite each other’s work? What the hell are SAS folders? Why do we need them and how are they different from the operating system folders and directories?

Let’s make everything straight. This post will explain the two distinct dimensions to a SAS BI environment: folder structure and software lifecycle environments. It will also provide some suggestions on how you can set up your SAS Business Intelligence environment the right way. Read More »

Post a Comment

Can my SAS application be grid enabled?

This blog is a continuation of an earlier blog entitled “To grid or not to grid?” In that blog, one of the reasons to say “yes to SAS Grid” is to see if you can gain some performance improvements from modifying your existing SAS processes by converting them to a distributed processing format. If improving performance of individual SAS applications is one of your reasons to implement SAS Grid Manager, please read on.

To start with, all of your existing SAS jobs can run on your new SAS Grid, but not all of your existing SAS jobs can be turned into distributed processing applications that can be run simultaneously across multiple nodes of the SAS Grid. For example, processes that rely heavily on OLAP processing do not lend themselves to parallelization. Statistical analysis tasks that need to create a matrix in memory cannot be parallelized either.

When identifying SAS applications to modify for distribution across a SAS Grid, the first thing to look for is jobs that take many hours and even days to complete. In addition to long execution times, there are several profiles of SAS applications or jobs that are good candidates for running in parallel across a SAS Grid. Read More »

Post a Comment

5 best practices for a world-class SAS environment

SAS administration and support can be a real challenge for some companies. It all has to do with not having the right resources and skills.

Business analysts are often charged with maintaining SAS. They know data, but they don’t have the IT skills needed to properly support SAS. IT teams face similar challenges because their experience lies in Windows, Linux and Oracle administration.

SAS administration requires specialized knowledge that typical IT teams do not have on hand. Over the last 10 years, my colleagues and I have found that SAS support requires IT skills, knowledge of the company’s data and knowledge of how that data gets applied to solve specific business problems. 

Companies that want a world-class SAS environment need to have dedicated resources who can proactively maintain SAS. With a dedicated resource, you'll be well-positioned to increase performance, minimize downtime and ultimately maximize your investment in SAS software. Read More »

Post a Comment

To grid or not to grid?

Let’s be honest.  When well planned, a SAS Grid Computing platform as the basis for a shared, highly available, high-performance analytics environment can pay for itself many times over. However, it is critical that your overall objectives and computing environment be well understood for you to achieve success with your SAS Grid implementation and to get the maximum benefit.

This post is the first in a series that will explore some of the best practices in setting up a high-performance, high-availability SAS analytics environment, but first let’s take time to understand what you can expect from a grid implementation: Read More »

Post a Comment

User group grants and awards: applicants needed!

Really!

I did a double-take last week when a conference chair told me that there’s grant money available for students, faculty and SAS junior professionals but few have applied. In one case, there were no applications submitted. We're hoping this is just a temporary glitch, a holdup resulting from too-busy schedules at the end of the academic year or too many work deadlines.

Every regional SAS users group and many of the local users groups offer grants and scholarships, and they’re excellent opportunities for professional development. The criteria, focus and programs may vary from one user group to another, but there’s one thing all user groups have in common—their enthusiasm for encouraging and developing the next generation of SAS professionals.

Applications are still being accepted for many of these awards.  So please check out the regional users group nearest you and take advantage of these opportunities today! Read More »

Post a Comment