Drawing overlays on SAS-generated Google maps

In this post, I am going to expand on my prior posts, Spice up SAS output with live Google maps and Live Google maps in SAS -- multiple markers to explore some new functionality.

Using similar techniques, I'll demonstrate how to draw a closed geometric shape, in particular, a polygon, on a Google map. Well, let’s make it more than one polygons – two for simplicity. Overlaying polygons on a Google map is a great visualization for geographical and administrative regions, such as countries, states, counties, school districts, areas of services, etc. Besides, practically any shape can be approximated by a polygon with a large enough number of vertices. Here's an example what we are going to get:

google_polygon1

The map is rendered with semi-transparent colors as fill colors for the polygon areas and a one-pixel solid color (stroke color) for the polygon borders. Actually, border lines are not necessary if adjacent areas are of different colors.

I have also included a technique for creating an information window object that displays information pertinent to each polygon region.  The code has an event listener that shows the corresponding information in the information window when a user clicks in the area of a polygon.

How it's done

You can view and download the full sample SAS code. Here are explanations and clarifications for each code 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 self-contained, I generated the source SAS table within the code itself.  In reality, you would prepare your data table by pulling or combining data from a database or other data storage. The source data has one observation per each vertex of each polygon. The data set variables include a region identifier (region), region color (aclor), region area in square miles (area), population, and latitude (lat) and longitude (lng) as shown here:

google_polygon2

3. Determine the map center. Center your Google map based on the geometrical center between minimum and maximum latitudes and longitudes of all polygons’ vertices:

proc means data=regions noprint;
  var lat lng;
  output out=dataspan (keep=minlat maxlat minlng maxlng) min(lat)=minlat
        max(lat)=maxlat min(lng)=minlng max(lng)= maxlng;
run;

data centerdata;
  set dataspan;
  clat = minlat + (maxlat - minlat)/2;
  clng = minlng + (maxlng - minlng)/2;
run;

4. Initialize the map. This section is not different from our prior implementations of the Google map with markers and info windows and uses a DATA _NULL_ step to generate a non-repeatable section of the code.

5. Add multiple regions. 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 it.

First, latitude-longitude pairs of all the vertices of each polygon are written into a Javascript array (called border), and then each polygon is created and overlaid on the Google map (google.maps.Polygon({paths: border, … ).

In this code section, for each polygon (mypoly1, mypoly2), we also create contents of the info window (info1, info2) and define event listeners (google.maps.event.addListener).

6. Wrap up the HTML file.  Again, this section is not different from our prior implementations of the Google map with markers and info windows and uses a DATA _NULL_ step to generate a non-repeatable section of the code to wrap up the Javascript and HTML.

Using the final Google map

Running the above code sample produces the gmapoutput_poly.html file, which, when opened in a web browser, produces the following Google map containing two polygon areas:
google_polygon3

Click for an interactive version of the map.  You can move it around, zoom in and zoom out, and you can click on any colored polygon to display detail information about that area in a popped information window as shown in Figure 1. The info window is opened at the point clicked by the user, but displays information about the whole polygon area. You can also switch between the Map and Satellite views.

If you are interested in Google map visualizations in SAS applications, please send me your ideas and desired functionality by commenting on this blog post.

Post a Comment

SAS Global Forum 2015—the place to learn more about analytics

Ever wondered where to find analytics experts to get your countless questions answered or where to find qualified talent to grow your industry? The simple answer to these questions is just one event – SAS Global Forum 2015 in Dallas, TX April 26-29.

Every year, the SAS Global Users Group plans and sponsors SAS Global Forum where SAS’s cutting edge technology gets showcased along with dozens of workshops, presentations, demos and networking opportunities. This is also the place you can learn how industry giants are using hot technologies such as visual analytics, Hadoop, in-memory computing and more.

Now, supersized datasets with billions of rows are the norm rather than the exception. Equally important, the variety of data being analyzed – from numeric to text to audio to video – has grown tremendously. Where can you see cool applications using such diverse data for making better decisions? From beginner to expert, from academic to commercial – SAS Global Forum 2015 has something to offer every skill level and application. Read More »

Post a Comment

SAS Visual Analytics 6.4: Importing a Twitter Stream

Great news.  If you’ve been struggling to import a Twitter stream as a data source, SAS Visual Analytics 6.4 has greatly simplified that task as part of this release’s expanded data import functionality. The first time you import tweets, you are directed to the Twitter website to log on to your account and authorize SAS Visual Analytics. After the initial logon, SAS Visual Analytics uses authorization tokens for accessing Twitter instead of requiring you to log on each time.

 The product documentation provides high level instructions for how to import tweets from Twitter, but I found that additional detail makes the process much simpler to follow.  In this post, I’ll walk you through the process from beginning to end, with screenshots and helpful hints along the way. Read More »

Post a Comment

8 most attended SAS administrator papers in 2014

In a comment on last week’s blog asking SAS administrators: please submit your paper idea for SAS Global Forum 2015, Andrew Howell of ANJ Solutions asked if I had any statistics on which were the most popular SAS administrator papers for last year’s conference. He suggested the following nominations although he was “only able to attend about half of these presentations—there was just so much to see!” 

I don’t have any readily available statistics on downloads for these papers, and, like Andrew, I wasn’t able to attend all of the excellent SAS Administrators sessions at SAS Global Forum 2014. But based on my own observations and feedback from others who were able to attend, here’s my very subjective ranking of Andrew’s list!

  1. Effective Usage of SAS Enterprise Guide in a SAS 9.4 Grid Manager Environment, Edoardo Riva, SAS
  2. SAS Grid – What They Didn’t Tell You, Manuel Nitschinger, sIT Solutions and Phillip Manschek, SAS
  3. Best Practices for Implementing High Availability for SAS 9.4, Cheryl Doninger, Zhiyong Li and Brian Wolfe, SAS
  4. SAS Installations: So You Want To Install SAS?, Rafi Sheikh, Analytics International
  5. Top 10 Resources Every SAS Administrator Should Know About, Margaret Crevar and Tony Brown, SAS
  6. SAS Grid Manager I/O: Optimizing SAS Application Data Availability for the Grid, Gregg Rohaly and Harry Seifert, IBM
  7. Test for Success: Automated Testing of SAS Metadata Security Implementations, Paul Homes, Metacoda
  8. Integrating Your Corporate Scheduler with Platform Suite for SAS® or SAS® Grid Manager, Paul Northrop, SAS Australia

Last year’s conference was a great opportunity for “seeing SAS Administrators in their natural habitat”.  Many of these sessions were standing room only.  Please submit your paper idea and let’s plan for another great year for administrators!

Post a Comment

Macro quoting made easy

Are there times when you need to pass special characters to a macro variable but cannot find the right technique to accomplish the task?  In this article I’ll discuss the different macro quoting functions and give a simple technique to help you determine which macro quoting function to use.

Why do we need macro quoting?  The SAS macro language is a character-based language. With macro, you can specify special characters as text.  Some of these special characters (for example, a semicolon or percent sign) are part of the SAS language instruction set, so we need a way for the macro processor to interpret a particular special character when it’s being used as text in the macro language.  Macro quoting functions tell the macro processor to treat these special characters as text rather than as part of the macro language.  Without macro quoting functions, you would have no way to mask the real meaning of these special characters or mnemonics.

This post will list some all-purpose functions, tell how to determine when to use each type, and show you how to unmask, or unquote special characters. Read More »

Post a Comment

SAS administrators: please submit your paper idea for SAS Global Forum 2015

The SAS Global Forum 2015 Call for Papers opened the end of last month!  I cannot believe it is time to start getting ready for the conference that will be in Dallas, TX on April 26-29, 2015.

As part of the group from SAS who goes to the conference each year to help the attendees with their administration questions, I would like to issue a personal invitation to all the readers of this blog to submit an abstract on SAS administration tips that have made your role as the SAS Administrator at your site easier, or things that you wish you had known before you took over the role of SAS Administrator.  These tips can be from setting up your hardware infrastructure to deploying your SAS applications to supporting your SAS users. Read More »

Post a Comment

MWSUG 2014 – guided learning, a cruise and more

MWSUG 2014 logo showing Chicago skyline and 25th anniversary bannerThis fall, you’ll be swept off your feet in the Windy City: The 2014 Midwest SAS User’s Group (MWSUG) takes place in Chicago from October 5-7. With 135 presentations in 11 different sections, you’ll have the chance to expand your SAS know-how and network with fellow SAS professionals. Read More »

Post a Comment

SAS administrators--what's on your bookshelf?

I spend a lot of time on support.sas.com looking for resources to share.  The SAS Programmer’s Bookshelf is a handy reference that’s been around for a while, so I asked “Why not a SAS Administrator’s Bookshelf?”

What would you include?

It’s complicated, of course, because the SAS administrator’s role covers a myriad of tasks. Throw into that mix, the fact that many individual software products have their own administration requirements, and you have quite a long list.

About a year ago, I published a post on SAS administrator connections and resources, and all this research made me realize it might be time to update that post with a few new items (noted with *). Read More »

Post a Comment

SESUG 2014—learning, networking, problem-solving

SESUG_2014Sun, surf and SAS await you at this year’s South East SAS Users Group (SESUG) conference. Located at the beautiful Myrtle Beach, South Carolina from October 19-21, the conference offers two full days of learning, networking and problem-solving.

“Every year I’ve attended, I’ve found something that I could immediately use in my job and brought back contacts I could reach out to if I needed help with a new SAS application,” said Barbara Okerson, SESUG Executive Council Member. “Once you come to the conferences and meet other SAS professionals, you realize that it’s a community of friends that are always willing to help each other.”

Read More »

Post a Comment

Partitioning in Hadoop, sorting in SAS--same results, different methods

SAS In-Memory Statistics for Hadoop is a single interactive programming environment for analytics on Hadoop that  integrates analytical data preparation, exploration, modeling and deployment. It’s principle components are the IMSTAT procedure (PROC IMSTAT) and the SAS LASR Analytic Engine (or SASIOLA engine for input-output with LASR).

Within the SAS In-Memory Statistics for Hadoop environment, the SAS LASR Analytic Engine provides most of the functionality we associate with Base SAS; whereas, PROC IMSTAT covers the full analytical cycle from data manipulation and management, through modeling, towards deployment. This duality continues SAS's long standing tradition of  getting the same job done in different ways, to accommodate users' different style, constraints and preferences.

This post is one of several upcoming posts I plan to publish soon that discuss code mapping of key analytical data exercises from traditional SAS programming to SAS In-Memory Statistics for Hadoop. This post today covers sorting and sorting-related BY variables and ordering in SAS In-Memory Statistics for Hadoop. Read More »

Post a Comment