Category Archives: Maps

Introducing MBA Maps

Street Level Mapping and Location Analytics for the rest of us


Over the years we have seen the importance of visual presentation of data using charts and graphs. In our minds, it’s equally important to be able to present data in the form of maps. Whether you are interested in presenting your data at the street level or at a higher geographic level, maps are a great way for viewing spatial relationships.

Here at MineQuest we’ve been working on creating a hybrid mapping service for WPS users. Our first release of the software called MBA Maps (MineQuest Business Analytics Maps) is a first cut at being able to use street level mapping to display data. This release (v0.1) is heavily weighted towards the utilities needed to manipulate data and interface into the cloud services that create the map tiles and perform the geocoding.

Initially, MBA Maps will be available on Windows workstation and followed by Mac workstations a bit later. Linux compatibility will also be made available as well as server platforms for Windows and Linux. We use the Interop for R (PROC R) procedure quite heavily to geocode and create maps. Specifically, we use David Kahle and Hadley Wickham’s ggmap tools for creating street level maps. We use WPS for the data processing and background program creation that manages the mapping calls. WPS is also used as the standard interface for all data management. Meaning, we store all our data in WPS data sets.

We will be releasing the first version of MBA Maps in January. Almost all the programming has been completed and testing continues. The documentation is still a work in progress and is about 50+ pages in length. There are numerous examples (see below) that are used in the documents, but we want to add some additional sample programs to the release. We’re strong believers in learning from code examples around here. We are also trying to include some data sets for learning how to use MBA Maps.

We anticipate creating a free version of MBA Maps that will be limited to using Google services. There are some restrictions by Google and they are a maximum of 2,500 records that can be geocoded a day and 2,500 map requests per day.

Eventually, and sooner rather than later (goal is 2nd quarter 2018) we will create a set of licenses so that those customers who have purchased their WPS licenses through MineQuest will receive a highly enhanced version of MBA Maps as part of their WPS purchase. This enhanced version will allow for using other services for geocoding and mapping. Services such as Bing and OSM will be provided. Access to a remote server hosted by MineQuest may also be included.

Those who purchase their licenses from other resellers or directly from World Programming will have the opportunity to acquire MBA Maps as a separate purchase from MineQuest. Pricing is undecided at this time but there will be an annual license and you will have to renew your MBA Maps licenses through MineQuest to access these additional features and services.

All versions will require a registration and license agreement.

What exactly does MBA Maps do? It allows you to create street level maps and geocode your data. If you have a small number of records to geocode (less than 2500 a day) and a small number of maps to display (also less than 2500), MBA Maps is probably all you need to create and display maps of your data.

If you have larger needs than the 2500 limitation for maps and geocoding, then you will need the non-free version of MBA Maps to get around those limitations. That will be available at a later date.

Here are a few examples of what you can do with MBA Maps.

MBA Maps can geocode a City name, a place in a city such as a park or monument or an address. In the next few pages are examples of creating a “street map” using Google map tiles and placing position markers and labels on the map.


This first example demonstrates placing a city on a map and labeling it. The data used was geocode at the City level (i.e. places) and using that to create and display the map.


Code used to create Midwest State Capitals.

libname mapdata ‘c:\mbamaps\mapdata’;




title=”Midwest State Capitals \nUnited States”,

footnote=”Google Map Created by MBA Maps \nMineQuest Business Analytics LLC \nCopyright (c) 2017″,








The second example is plotting attractions on the map. Here we geocoded some London attractions using the name of the attractions. We then use the name of the attraction (variable name site) as the label on the map.


Code for creating London Attractions Map




title=”London Attractions, 2017″,

footnote=”Google Map Created by MBA Maps \nMineQuest Business Analytics LLC, \nCopyright (c) 2017″,


mapwidth=8, mapheight=11);






The third example is a map of gas stations in Powell, Ohio. We first geocoded the addresses of the gas stations to get their proper latitude and longitude. We then took the geocoded addresses and used them to plot the points on a street map. This demonstrates plotting of addresses on a map.


Code for Creating Powell Ohio Gas Stations Map.





 title=”Powell Ohio Gas Stations \nUnited States”,

 footnote=”Google Map Created by MBA Maps \nMineQuest Business Analytics LLC \nCopyright (c) 2017″,











Finally, our fourth example using MBA Maps demonstrates how we can even create a hybrid map. A hybrid map is a satellite view with street names embedded in the map. The map below uses the homes estimated value as a label for the marker. We geocoded a number of addresses at Skyline Country Club in Tucson, AZ. The records we used also contained a value of the homes current price. We used a hybrid satellite map to plot the addresses with the estimated home values on a Google map.


 Code for creating hybrid street level map.


  maptype=hybrid, label=homevalue,

  title=”Skyline 5th Fairway Home Values \nTucson AZ”,

  footnote=”Google Map created by MBA Maps \nMineQuest Business Analytics LLC \nCopyright (c) 2017″,


  mapwidth=11, mapheight=8);







Example code for geocoding street addresses which is used for the hybrid google map above.

libname mapdata ‘c:\mbamaps\mapdata’;


data a;

length homevalue $6;

input homeaddress $1-44 price 45-48;

homevalue = put(price,comma5.)||’K’;


4795 E Quail Creek Dr. Tucson AZ 85718       464

4779 E Quail Creek Dr. Tucson, AZ 85718      544

4757 E Cherry Hills Dr. Tucson, AZ 85718     470

4749 E Cherry Hills Dr. Tucson, AZ 85718     449

4880 E Placita Tres Vidas, Tucson, AZ 85718  799

4860 E Placita Tres Vidas, Tucson, AZ 85718 1795

4840 E Placita Tres Vidas, Tucson, AZ 85718  728




Proc print data=a;

Title “Data to be geocoded”;




%geocode(api=google, data=a, outdata=b, geocodevariable=homeaddress);


proc print data=b;

Title “Geocoded Home Addresses”;




*–> merge in the geocoded data set with the existing data set;


data homeprices;

merge a b;



This gives you an idea of what we will be introducing in January of 2018. We have lots of ideas behind our mapping and want to create a whole area of tools and applications for location analytics. Watch this space for an announcement of availability.


About the author: Phil Rack is President of MineQuest Business Analytics, LLC located in beautiful Tucson, Arizona. Phil has been a SAS language developer for more than 25 years. MineQuest provides WPS consulting and contract programming services and is an authorized reseller of WPS in North America.

Creating Maps with WPS and the Bridge to R

A while back, I demonstrated how you can use the Bridge to R to create almost any graph or plot using WPS in combination with R. I showed how you can create the cowboy hat as well as some basic and not so basic charts and plots. One thing that I didn’t demonstrate was how you can create thematic maps (aka chloropleth maps) using the Bridge.

Today, I want to delve into that area a little bit and provide some programming samples that you can use to create these maps. First, you need to have a copy of the Bridge to R and WPS (or SAS) to run these demos. Some of the later code also uses the county2000 dataset available from the downloads section of the website.

First a little background. Thematic mapping is a great way to show how certain attributes change or vary over given political boundaries. For example, depicting how states differ in terms of income tax assessment, or what are the most populous counties in the country. Providing a visual map for your users to understand variation across geography is always helpful in my opinion. R provides a library called “maps” that contains polygons for drawing thematic maps and a means for attaching a variable that you want to visually display demonstrating change over a given geography. I will show how you can use state and county outlines from R to do just that with the Bridge to R.

To draw a simple outline of the United States using the Bridge, it only takes three lines of R code. For example:

Program 1. Displaying U.S. State Outlines.

   1: *--> Outline of the United States - by state;

   2: %Rstart(dataformat=manual, data=, rGraphicsViewer=true);

   3: datalines4;


   5:  library(maps)  # load the boundary file

   6:  map("state", interior = TRUE, projection="polyconic", col="blue")

   7:  title('United States')  # draw the map


   9: ;;;;

  10: %Rstop(import=);

Map 1. U.S. State Outlines Map.


Click on map to view an expanded image

We can expand on the above map by adding one more line of code which will draw the county outlines inside of the state boundary outline.

Program 2: Creating State and County Outlines.


   2: *--> Outline of the United States - by state/county;

   3: %Rstart(dataformat=manual, data=, rGraphicsViewer=true);

   4: datalines4;


   6: library(maps)


   8:  map('county', boundary=TRUE,

   9:  interior=TRUE, projection="polyconic", col='lightgray', fill=TRUE, resolution=0, lty=1)

  10:  map('state', boundary=FALSE,

  11:      projection="polyconic", col='white', fill=FALSE, add=TRUE, lty=1)

  12: ;;;;

  13: %Rstop(import=);

Map 2. State County Outlines.

US_State_county_outline Click on map to view an expanded image

We can take this one step further by selecting only the geographic areas that we are interested in displaying by passing an argument to R passing just the regions we are interested in viewing. In this case, I’ve taken the liberty to pass the string containing the regions to R by using a macro variable. The Bridge to R can pass macro variables to R to help minimize typing and making mistakes.

Program 3. Selecting specific areas to map.

   1: *--> Great Lakes States by county - How to map a subset;

   2: %let geogarea = 'ohio','michigan','indiana','illinois','wisconsin';


   4: %Rstart(dataformat=manual, data=, rGraphicsViewer=true);

   5: datalines4;


   7: library(maps)

   8:  map('county',region= c(&geogarea), boundary=TRUE,

   9:  interior=TRUE, projection="polyconic", col='lightgray', fill=TRUE, resolution=0, lty=1)

  10:  map('state',region= c(&geogarea), boundary=FALSE,

  11:      projection="polyconic", col='white', fill=FALSE, add=TRUE, lty=1)


  13:  title('Great Lakes States')


  15: ;;;;

  16: %Rstop(import=);

When we run the code above (Program 3), we are presented with a map that just contains the counties for the Great Lakes States Ohio, Michigan, Indiana, Illinois, and Wisconsin.

Map 3. Great Lakes States.

greatlakes_states_county_outlineClick on map to view an expanded image

So far, I’ve shown you how to (1) create a map, (2) overlay two geographic areas (state and county) on a map, and (3) how to select a specific subset of the data to display (Great Lakes States) in creating your maps. Let’s move on and see how you can map your data using the Bridge to R and the R maps library.

The data I’m using to create the county population density map below is from a zip file that you can download from the MineQuest website. Basically, I’m using WPS to manipulate the data to get it into a format that R can use and then using the Bridge to R, call the mapping routines to display this data.

Program 4. Displaying your data in a thematic map.

   1: libname cntydata 'c:\data';


   3: proc format;

   4: value popval

   5: 0-24999 = 1

   6: 25000-99999=2

   7: 100000-249999=3

   8: 250000-499999=4

   9: 500000-749999=5

  10: 750000-high=6;

  11: run;



  14: data cntydata(keep=names cntypop);

  15:   set cntydata.county2000;

  16:   length names $ 32 cntypop 8;

  17:   cntypop = pop100;

  18:   if state in('02','15','72') then delete;

  19:   x=indexw(name,'County');

  20:   if x > 0 then cntyname=substr(name,1,x-1);


  22:   y=indexw(name,'Parish');

  23:   if y > 0 then cntyname=substr(name,1,y-1);


  25:   names=trim(lowcase(fipname(state)))||','||trim(lowcase(cntyname));

  26:   format cntypop popval.;

  27: run;



  30: *--> great a US map at county level showing population density;

  31: %Rstart(dataformat=csv, data=cntydata, rGraphicsViewer=true);

  32: datalines4;


  34: library(maps)  # Load the maps library

  35: popdata <- (cntydata)


  37: #define the color map to be used

  38: cols <- c("#F1EEF6", "#D4B9DA", "#C994C7", "#DF65B0", "#DD1C77", "#980043")


  40: mp <- map("county", plot=FALSE,namesonly=TRUE)

  41: # draw the county outlines

  42: map("county", col=cols[popdata[match(mp,popdata$names),]$cntypop],fill=TRUE, projection="polyconic")


  44: # Draw the state outlines

  45: map('state', boundary=FALSE,projection="polyconic", col='white', fill=FALSE, add=TRUE, lty=1)


  47: title('U.S. County Population Density')

  48: ;;;;

  49: %Rstop(import=);

Map 4. U.S. County Population Density.

us_state_county_pop_2000 Click on map to view an expanded image

Above is the map generated by the code in Program Listing 4. Personally, I think it’s a nice thematic map and does demonstrate population density by county. It obviously can be enhanced by adding a legend and perhaps a footnote, but I will leave that up to you to figure out. The code that creates the map is only seven lines long. This could easily be made into a template by users for further expanding the map as well as for code reuse purposes.

For more information on creating maps with R, visit Cran at: and download the maps.pdf file.

About the author: Phil Rack is President of MineQuest, LLC. and has been a SAS language developer for more than 25 years. MineQuest provides WPS and SAS consulting and contract programming services and a reseller of WPS in North America.