Monday, December 30, 2013

SAS and Bing Maps API

Here is a method for using SAS and Bing Maps:

  1. Signed up for a key on Bing Maps API. Create a basic key and copy it somewhere. I will demonstrate it in the SAS code as [BINGKEY] since I cannot share mine publicly: https://www.bingmapsportal.com/

  2. Use the following code:
  3. %let z1=47.64054;
    %let z2=-122.12934;
    %let BINGKEY=%NRSTR(&key=[BINGKEY]);

    filename x url "http://dev.virtualearth.net/REST/v1/Locations/&z1.,&z2.?o=xml&BINGKEY";
    filename z "c:\temp\BingMap.xml";

    data _null_;
    infile x ;
    file z ;
    input;
    put _INFILE_;
    run;

  4. Parse the xml that is produced as needed. You can also output it as JSON if you change the word xml in the URL to json.

2 comments:

Mark said...

Hi Alan, thanks for the blog post. I'm having some issues with using my Bing Key with SAS. I have used it successful to geocode addresses in excel using the excel-geocoding-tool 3.6.xls, but when I try to the SAS code you provided, I'm getting the following authorization error: Copyright © 2014 Microsoft and it s suppliers. All rights reserved. This API cannot be accessed and the content and any results may not be used, reproduced or transmitted in any manner without express written permission from Microsoft Corporation.

Savian said...

Have you changed the BINGKEY to your own? Also, does it work in a browser?

SAS throwing RPC error

If you are doing code in C#  and get this error when creating a LanguageService: The RPC server is unavailable. (Exception from HRESULT:...