<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: determine country name from GPS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/determine-country-name-from-GPS/m-p/260875#M50670</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Google offers a web service for their maps API to do just that.&amp;nbsp; For low volume queries they do not charge you anything but you will have to register and obtain a key. Yoou can use proc http to send the request and parse out the json returned result in a datastep.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is the code I use. Use macro processing to cycle through a list of coordinates. Perhaps it's not the quickest way and can probably be improved (hope someone will point out how) but it was surely fun to see it work. For my purpose, finding start and end points of my tracked car trips, it is more than sufficient.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let lat=35.828713;&lt;BR /&gt;%let lng=-78.767082;
&lt;BR /&gt;%let url=https://maps.googleapis.com/maps/api/geocode/json?latlng=&amp;amp;lat.,&amp;amp;lng.%str(&amp;amp;)location_type=ROOFTOP%str(&amp;amp;)result_type=street_address%str(&amp;amp;)key=wouldntyouliketoknow;

proc http out=location method='get' url="&amp;amp;url" headerout=hdrs;
run;

data address;
        infile location;
        length rec property formatted_address $512;
        start= 1;
        keep latitude longitude formatted_address;
        retain re formatted_address;
        if _n_=1 then do;
                re=prxparse('/"[^"]*"/');
        end;
        input;
        rec = _infile_;
        call prxnext(re, start, -1, rec, position, l);
        if position &amp;gt; 0 then do;
                property = substr(rec, position+1, l-2);
                if strip(property)="formatted_address" then do;
                        call prxnext(re, start, -1, rec, position, l);
                        formatted_address = substr(rec, position+1, l-2);
                        latitude = &amp;amp;lat;
                        longitude = &amp;amp;lng;
                        put latitude= longitude= formatted_address=;
                        output;
                        stop;
                end;
        end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This prints out&lt;/P&gt;
&lt;PRE&gt;latitude=35.828713 longitude=-78.767082 formatted_address=100 SAS Campus Dr, Cary, NC 27513, USA&lt;/PRE&gt;
&lt;P&gt;As I said perhaps not the quickest way but it was surely fun to see it work. And the Google API is very verstile.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;- Jan.&lt;/P&gt;</description>
    <pubDate>Sat, 02 Apr 2016 07:24:54 GMT</pubDate>
    <dc:creator>jklaverstijn</dc:creator>
    <dc:date>2016-04-02T07:24:54Z</dc:date>
    <item>
      <title>determine country name from GPS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/determine-country-name-from-GPS/m-p/260671#M50624</link>
      <description>&lt;P&gt;If I have a dataset with GPS locations, can I determine the country these coordinates are in?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, consider the following dataset:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
    input sn lat long;
    datalines;
    1 57 -112
    2 30.2 -97.7
    ;
run;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;How can I add a new column extracting the country name from gps if possible?&lt;/P&gt;</description>
      <pubDate>Fri, 01 Apr 2016 11:34:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/determine-country-name-from-GPS/m-p/260671#M50624</guid>
      <dc:creator>dwsmith</dc:creator>
      <dc:date>2016-04-01T11:34:41Z</dc:date>
    </item>
    <item>
      <title>Re: determine country name from GPS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/determine-country-name-from-GPS/m-p/260875#M50670</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Google offers a web service for their maps API to do just that.&amp;nbsp; For low volume queries they do not charge you anything but you will have to register and obtain a key. Yoou can use proc http to send the request and parse out the json returned result in a datastep.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is the code I use. Use macro processing to cycle through a list of coordinates. Perhaps it's not the quickest way and can probably be improved (hope someone will point out how) but it was surely fun to see it work. For my purpose, finding start and end points of my tracked car trips, it is more than sufficient.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let lat=35.828713;&lt;BR /&gt;%let lng=-78.767082;
&lt;BR /&gt;%let url=https://maps.googleapis.com/maps/api/geocode/json?latlng=&amp;amp;lat.,&amp;amp;lng.%str(&amp;amp;)location_type=ROOFTOP%str(&amp;amp;)result_type=street_address%str(&amp;amp;)key=wouldntyouliketoknow;

proc http out=location method='get' url="&amp;amp;url" headerout=hdrs;
run;

data address;
        infile location;
        length rec property formatted_address $512;
        start= 1;
        keep latitude longitude formatted_address;
        retain re formatted_address;
        if _n_=1 then do;
                re=prxparse('/"[^"]*"/');
        end;
        input;
        rec = _infile_;
        call prxnext(re, start, -1, rec, position, l);
        if position &amp;gt; 0 then do;
                property = substr(rec, position+1, l-2);
                if strip(property)="formatted_address" then do;
                        call prxnext(re, start, -1, rec, position, l);
                        formatted_address = substr(rec, position+1, l-2);
                        latitude = &amp;amp;lat;
                        longitude = &amp;amp;lng;
                        put latitude= longitude= formatted_address=;
                        output;
                        stop;
                end;
        end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This prints out&lt;/P&gt;
&lt;PRE&gt;latitude=35.828713 longitude=-78.767082 formatted_address=100 SAS Campus Dr, Cary, NC 27513, USA&lt;/PRE&gt;
&lt;P&gt;As I said perhaps not the quickest way but it was surely fun to see it work. And the Google API is very verstile.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;- Jan.&lt;/P&gt;</description>
      <pubDate>Sat, 02 Apr 2016 07:24:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/determine-country-name-from-GPS/m-p/260875#M50670</guid>
      <dc:creator>jklaverstijn</dc:creator>
      <dc:date>2016-04-02T07:24:54Z</dc:date>
    </item>
  </channel>
</rss>

