Tag Archives: Bridge to R

Plotting Points on a Street Level Map using the Bridge to R and WPS

In the last few installments of this blog, I have shown how you can use WPS and the Bridge to R to calculate drive distances, geocode records and pull down a map from Google maps. I want to use this post to pull all this together and show how you can geocode your addresses and plot them on a street level map.

First some background you need to know about using Google for geocoding and mapping. There are limits to what Google will allow you to do with their services before they want you to start paying. You can geocode 2,500 records a day for free. You can pull down 25,000 maps a day for free. Once you start moving past these limits, there are fees involved.

One thing that you should probably start to consider is caching records locally that have been geocoded so that you don’t have to go back to the Google geocoder every time you want to plot some points on a map. I could easily run through 2,500 addresses in a day. The limitations on the number of maps is just not an issue for me. I think 25,000 maps a day is a very liberal offering for the kind of work that I would want to use the service for.

In the sample code below, I split the mapping process into two components for ease in understanding the entire process. I first geocode the file to get the latitude and longitude for each record. The second part of the process is creating a map and using the lat’s and long’s to plot points on the map. We could have put this into a single step but it wouldn’t be as clear or as flexible.

Without further ado, here’s the code using the Bridge to R and WPS.

data gasstations;
input company $1-29 address $30-52 city $53-64 state $66-67;
addr2geocode=trim(address)||', '||trim(city)||', '||trim(state);
cards;
Citgo Gas Station            5189 28th St Se        Grand Rapids MI
28th Street BP               5155 28th St Se        Grand Rapids MI
Twenty-Eighth Street C Store 5556 28th St Se        Grand Rapids MI
Speedway                     4045 28th St Se        Grand Rapids MI
Speedway                     2305 E Paris Ave Se    Grand Rapids MI
Superamerica                 2305 E Paris Ave Se    Grand Rapids MI
Shell Food Mart              3960 28th St Se        Grand Rapids MI
Admiral Petroleum            3927 28th St Se        Grand Rapids MI
Cascade C Store              4591 Cascade Rd Se     Grand Rapids MI
Friendly Food Shops          6799 Cascade Rd Se     Grand Rapids MI
Family Fare Quick Stop       6799 Cascade Rd Se     Grand Rapids MI
Cascade Citgo                6820 Cascade Rd Se     Grand Rapids MI
Dutton Fuel Mart LLC         2560 E Beltline Ave Se Grand Rapids MI
Centerpointe Marathon        2560 E Beltline Ave Se Grand Rapids MI
Shell Food Mart              2600 E Beltline Ave Se Grand Rapids MI
Speedway                     4018 Cascade Rd Se     Grand Rapids MI
Grand Rapids Gas Incorporated3214 28th St Se        Grand Rapids MI
Cascade Shell                4033 Cascade Rd Se     Grand Rapids MI
Speedway                     4665 44th St Se        Kentwood     MI
Super Petroleum Incorporated 2411 28th St Se        Grand Rapids MI
;;;;
run;


*--> Geocode the addresses using the Google Geocoder. Keep the geocoded records
     in the output dataset names locs for further processing.;

%rstart(dataformat=csv,data=gasstations,rGraphicsFile=);
datalines4;

## options(repos=structure(c(CRAN="http://cran.case.edu/")))
## install.packages("ggmap", dependencies = FALSE)

   attach(gasstations)

   library(ggmap)

   gaddress <- as.character(gasstations$addr2geocode)
   locs <- geocode(gaddress,output="more")

;;;;
%rstop(import=locs);


*--> Pull a Google map that is centered on a particular address and plot the locations
     on the map. Use the data set that was created (locs) above that contains the 
     lat and longs to plot the points.;
     
Title 'Gas Stations on or Near 28th Street';
Title2 'Grand Rapids, Michigan';     
     
%rstart(dataformat=csv,data=locs,rGraphicsFile=);
datalines4;

attach(locs)
addr <- locs;

library(ggmap)

map.center <- geocode('3960 28th St Se, Grand Rapids, MI');

 grmap <- qmap(c(lon=map.center$lon, lat=map.center$lat), zoom = 13,color = 'color', legend = 'topleft')
          grmap +geom_point(aes(x = lon, y = lat, size=3.0), data = addr)

;;;;
%rstop(import=);

The map that is created looks like this:

GR_Stations

I cropped this down a bit and got rid of the borders so that it would be easier to view on this blog. Note the black points on the map that indicate the locations of the gas stations. We could continue this exercise by plotting a label to the points with the names of the service stations but that would be a good exercise for the reader who wants to learn more about using ggmap and street level mapping.

If you want to learn more about ggmap and street level mapping, I encourage you to take a look at the following document, “ggmap: Spatial Visualization with ggplot2 – the R Journal” and can be viewed in PDF format here. What I have presented is really a quick and dirty set of examples that just begin to scratch the surface of what ggmap can do for you.

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

Creating a Street Level Map with WPS and the Bridge to R

Creating a street level map using the Bridge to R and WPS is actually pretty easy. As in our other examples (see the two previous blogs) we again use ggmap to pull down a map from Google Maps and display it using HTML. Amazingly, this only takes four lines of R code. Here’s an example:

 

%rstart(dataformat=man,data=,rGraphicsFile=);
datalines4;

   library(ggmap)

   bp <- "4045 28th St Se, Grand Rapids, MI, USA"
   qmap(bp, zoom=12)
   print(bp)

;;;;
%rstop(import=);

The code is fairly easy to follow. We load the ggmap library that will do most of the work for us. We center the map using the address “4045 28th St Se, Grand Rapids, MI, USA”. The next line queries the map with a specified zoom level (we are using zoom level 12). Finally, we print the map using the print function.

This is what the map looks like.

b2rplt_1700486050_2_1

 

We can actually take this a bit further. Instead of using a known address, we can us a place of interest for querying and creating the map. If we replace the address in the code above with “White House, Washington DC, USA” we get a map like below.

b2rplt_1700487946_3_1

So know we have seen how easy it is to pull down a map from Google using ggmap and the Bridge to R for WPS. If you have a copy of the Bridge to R, I recommend you play with the demonstration programs to get an idea of what you can do with the software and the mapping service. It’s always fun to see what gets rendered using ggmap, R and the Bridge to R.

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

Calculating Driving Distances with WPS and the Bridge to R

A few weeks ago, there was a posting on SAS-L where the poster was attempting to get the driving distance between two cities using google’s mapping services. I found that a rather interesting question and decided to see what I could do using WPS and the Bridge to R.

For those who are unfamiliar with the Bridge to R, it is a product from MineQuest Business Analytics that allows you to execute R statements from within the WPS environment. You can pass WPS datasets to R and return R frames to WPS quite easily. You also get the R log and list files returned to your WPS session in the corresponding log and list windows.

Here is the code that we used to create a driving distance matrix between three cities. The output is printed using the PROC Print statement in WPS. 

*--> data set for drive distances;
data rdset;
input fromdest $1-17 todest $ 20-36;
cards;
Grand Rapids, MI   State College, PA
Columbus, OH       Grand Rapids, MI
Chicago, IL        Grand Rapids, MI
;;;;
run;


%Rstart(dataformat=csv,data=rdset,rGraphicsFile=);
datalines4;

    attach(rdset)
    library(ggmap)

    from <- as.character(fromdest)
    to  <- as.character(todest)

    mydist <- mapdist(from,to)

;;;;
%rstop(import=mydist);

proc print data=mydist(drop=var2);
format m comma10. km comma 8.2 miles 8.2 seconds comma7. minutes comma8.2 hours 6.2;
run;

And this is the output:

      Obs    from                  to                              m          km       miles    seconds     minutes     hours       
                                                                                                                                    
       1     Grand Rapids, MI      State College, PA         843,978      843.98      524.45     28,256      470.93      7.85       
       2     Columbus, OH          Grand Rapids, MI          521,289      521.29      323.93     17,543      292.38      4.87       
       3     Chicago, IL           Grand Rapids, MI          285,836      285.84      177.62      9,695      161.58      2.69       
                                                                                                                             

So you can see how handy WPS and the Bridge2 to R can be as a resource – kind of a Swiss Army knife if you like.

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

What are the benefits when buying from MineQuest?

I’m often asked what are the benefits of buying a WPS license from MineQuest Business Analytics?

There are many, but I will touch on three of them in this post. First, when you purchase your server licenses from MineQuest, we provide a means of protecting your license investment. If you find that you need to scale up your server from say four to eight cores in the middle of your license period, we can upgrade your license so that you don’t lose money in the transition. We do require that you stay on the same operating system, but other than that, you get full credit for the time remaining on your license when you trade up.

The second benefit is that you automatically get a copy of the Bridge to R. The Bridge to R allows you to interface WPS into the R system for running more advanced statistical routines and enhanced graphics.

Third, we offer a first line of support for our customers. We have a few years of WPS experience under our belt and have developed products based on WPS. We know the product relatively well and we provide consulting services to companies needing it. We can implement WPS Link (i.e. submit programs from a desktop to a WPS Server) for customers who want a client server environment on any x86 architecture and help with installation and product overviews to users.

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

Bridge to R Study Edition now available

After giving some consideration to creating a Study Edition of the Bridge to R, we finally have put the package together. Starting on Friday, May 18th, you can request a download package for the Bridge to R SE to use to learn and experiment with using WPS.

The Bridge to R SE is limited to reading 1500 records from a WPS dataset and passing those observations on to R. This should be sufficient for testing your R programs running in WPS and to learn the language nuances of the Bridge to R.

For more information and download instructions, go to the Bridge to R SE page. There’s also a short video that shows what the Bridge to R can do for you.

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 is a reseller of WPS in North America.

Life with a Mac Mini

Well I finally decided to break down and buy a Mac Mini. I’ve used Apple products before but have never become a fan because my consulting business has been mostly Windows platforms. I’ve also enjoyed the OS wars as it pertains to the Apple faithful and the Windows users.

One thing I’ve noticed is when I go to a college campus, the number of Apple computers to Windows computers. I ask nieces and kids of friends of mine who go to major universities the ratio of Apple computers to Windows computers. I’ve received feed back that the ratio is as high as 15 to 1 at some schools and the lowest has been a one-to-one ratio. That’s astounding to me and when I do visit a college campus, I often see at least a three to one ratio of Apple computers to Windows computers.

I brought the Mac Mini home and setup couldn’t be easier. It took literally five minutes to take it out of the box, plug the cables in, and press the start button. One thing I didn’t appreciate was the price gouging for extra memory. Apple wanted an extra $300 to take the machine from 2GB of memory to 8GB of memory. I went out to Newegg and found 8GB of memory for $29 after a $10 rebate. That in my mind is a huge price savings.

So far, I’ve installed R, Libre Office, and of course some of my other favorite statistical packages. Performance is OK, nothing stellar. But I didn’t expect that to be the case with a single 2.5 inch hard drive either.

This is a pretty decent little machine for developing and writing software. One of my goals is to have the Bridge to R running on the Mac Mini using the Linux version of the Bridge to R. I don’t expect any hassles in this respect.

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.

PDF Support for the Bridge to R

We’re still developing and adding on to the Bridge to R and want to announce a major enhancement to the product. We will be supporting output to PDF under the Windows version. A number of customers have asked for PDF support and we believe adding this is an easy and quick way for our customers to start creating reports using a PDF destination.

Here is a code snippet that shows how you would create a PDF file. We introduce two new macros that do the work. The first one, %PDF takes the parameters for creating the PDF file. The second macro, %PDFClose terminates the code for what will appear in the PDF file.

   1: options ls=133 ps=60;

   2:

   3: %pdf(autoview=TRUE,

   4:      pdffile='c:\temp\pdfnewandbig.pdf',

   5:      pdfoptions= -pfn200 -pps4 -pfs8 -pot);

   6:

   7:    proc print data=a;

   8:       title 'Sample PDF Output using the Bridge to R';

   9:       footnote 'Generated the Bridge to R by MineQuest';

  10:    RUN;

  11:

  12:    Proc Means data=a n nmiss min max range std maxdec=4;

  13:    run;

  14:

  15: %pdfclose;

We allow you to add a number of parameters to modify the PDF output. The parameters above tell the macro which font to use (-pfn200), the page size (-pps4), the point size (-pfs8) and to use a landscape orientation (-pot). There are many other parameters that you can use including encryption.

The PDF functionality will be available in the next release of the Bridge to R which should be available by the end of October. There will be some updated documentation that will include PDF support and the new documents will remove any references to the Bridge running under the SAS System since we don’t support that any longer.

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.

Getting Caught Up

It’s been a while since I posted something on the blog. Things have been busy the last few months and the time to sit down and write a piece for the blog has suffered because of it.

One thing that may be of interest to a few of MineQuest’s customers is that we found a little bug in the Bridge to R. It’s nothing that would create an error but could create some confusion. Under certain circumstances, %MPEXEC (allows for a form of parallel processing in WPS) would write a note to the log stating that a macro variable was not resolved. This has been taken care of and that note will no longer be created.

I also noticed the other day that there has been a project in the R camp to read SAS7Bdat files. This is interesting because at the moment, the Bridge to R doesn’t directly read a SAS7Bdat file. Theoretically, this could improve processing speed because there wouldn’t be a middle process taking place that takes a WPD or SAS7BDAT data set and puts it into a form that R could read directly. I’ve been hoping that eventually I could read a WPD table directly but using a SAS7Bdat might be the answer to this dilemma. Some research is needed, but if the R library is stable, I may start writing code to directly read the SAS7Bdat by allowing the keyword DATAFORMAT=SAS on the %RStart() macro.

On the WPS front, we’re seeing a number of large organizations migrate over to WPS from SAS. Some companies are simply trying to practice good risk management and don’t want to be locked in to one provider of the language of SAS. Other’s are bringing WPS on board in an attempt to keep an arm’s length distance from the Institute and manage software costs more effectively. The most movement in this area is taking place on the Windows and Linux servers on x86. That is by far the biggest bang for the buck right now. The Linux platform is cost effective due to OS licensing and the fact that WPS doesn’t have client license fees. The platform is high performance and typically outruns Windows Server platforms. That’s a nice combination, lower price and better performance.

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.

Top 10 Reasons for WPS Popularity

I had an interesting discussion earlier in the week and was asked what I felt the Top 10 Reasons that WPS is gaining such popularity and notoriety as a SAS replacement. I had to think about that for a while, but I finally came up with these 10 reasons. They’re in no particular order of importance, so here it goes.

1. All modules are included for one reasonable fee.

2. Microsoft certified for 64-bit Operating Systems.

3. Eclipse GUI is an advanced interface and editor for programmers.

4. Server licenses are inclusive meaning no client license(s) required.

5. No data service provider fees.

6. No fat upfront license fees, just the same annual fee each year.

7. High performance sorting, easily out runs our competitors.

8. Simple point and click installation. No gigabyte installs or downloading of external files and the inevitable confusion and conflict over dependencies.

9. Third party interfaces allow you to use the hottest statistical libraries from the open source program R.

10. Native support for Macintosh running OS X on x86.

So if you’re a WPS user, do you have any favorite reasons?

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.

Background on the Bridge to R for WPS Users

I want to spend some time discussing a few issues surrounding the Bridge to R, it’s background and the philosophy of the product. I do get a number of inquiries on the Bridge so I think it would be prudent to talk about it as well as how we arrived at the pricing.

I created the Bridge to R originally as an exercise to see if I could run R programs from within WPS which is a SAS Language alternative software system. I wanted to be able to feed R data that was created and manipulated by the WPS System and get all the R output back into WPS. I worked on this over a period of a month and eureka! it worked. Since one programs WPS in the language of SAS, I was able to instantly port the Bridge to R to work directly with SAS without any changes.

Once I wrote some documentation, I put the Bridge to R out on the internets for both SAS and WPS users alike to use. The idea originally was to have the Bridge be able to work in hybrid environments — i.e. organizations using both SAS and WPS so that developers could use R in a very portable fashion. I had the Bridge to R out on the MineQuest website for four to six months and it had a reasonable number of downloads. There were many more SAS users who downloaded the Bridge than WPS users, but that is understandable considering the size of the user base.

I eventually came to the realization that SAS users were not really interested in using the Bridge to R as a method to write portable statistical routines between WPS and SAS, but instead were using the Bridge to R as a way to get around licensing SAS’s IML Studio product. The Bridge to R was a free download and had no pricing attached to it at the beginning. Since I was starting to resell WPS in North America, I was not thrilled by that because I want users to license WPS!

At that point, I felt it was necessary to pull back support on the Bridge to R for SAS Users and only offer it to WPS users. Being able to access R from within the WPS environment directly was a huge money saver in contrast to the SAS product offering and I felt that there should be a reward for SAS Language Developers and statistical analysts who want to use R to get the product at low cost or no cost.

At that point a decision was made to only support WPS and dropped support for SAS. There are numerous reasons for this decision and a few of the most pertinent ones are support costs, licensing a SAS development environment was prohibitive, and I wanted to offer an incentive to companies to purchase WPS licenses from my company, MineQuest.

After a fair amount of discussion, it was decided that MineQuest would provide a copy of the Bridge to R to any organization that licensed WPS from us on either Windows or Linux platforms. This copy of the Bridge is provided as a product from MineQuest that is totally separate from the WPS product created by World Programming LTD. Since MineQuest only resells WPS in North America, we only supply the Bridge to R with WPS to North American customers. So that’s the incentive, if you buy a WPS license from MineQuest and in North America, you get the Bridge to R as part of the purchase.

So what about WPS customers who are not from North America or who purchased their WPS licenses directly from World Programming? We still want to provide the Bridge to R to your company, but the economics of the situation dictate that we charge a small amount for the software. Currently, we charge $199 for the desktop version, and $599 for a server version of the Bridge.

I’ve been asked on the phone as well as by email, why I don’t distribute the Bridge to R to all WPS users. The answer is because there’s costs involved in the development, maintenance and support of the product. Every time a new version of WPS roles out or a new release of R hits CRAN, we make sure that the Bridge to R continues to operate on all the Windows platforms as well as on Fedora Linux and Ubuntu. We run a multitude of test programs on XP, Vista and Windows Server for both 32-bit and 64-bit installations as well as for the Linux platforms. All of this takes time and effort and quite honestly, we can’t do this for free. Hence, we charge WPS licensee holders a fee if they didn’t purchase their license from MineQuest.

So there’s the history and background on the Bridge to R and why we price it the way we do. I hope you understand that there’s significant cost in the development and support of the Bridge to R. The bottom line is that if having access to R is important to you for advanced analytical techniques and graphics, then you should strongly consider licensing your WPS software directly from MineQuest.

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.