<?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 how to convert a longitude and latitude coordinates into geohash in SAS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-convert-a-longitude-and-latitude-coordinates-into-geohash/m-p/540931#M149284</link>
    <description>&lt;DIV class="lia-component-thread-subject"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="lia-component-message-list"&gt;&lt;DIV class="linear-message-list message-list"&gt;&lt;DIV class="lia-linear-display-message-view"&gt;&lt;DIV class="first-message"&gt;&lt;DIV class="lia-message-view message-uid-540906"&gt;&lt;DIV class=""&gt;&lt;DIV class="lia-js-resize-images lia-component-forums-widget-board-message-view"&gt;&lt;DIV&gt;&lt;DIV class="lia-panel-message-root lia-message-board lia-panel-message lia-js-data-messageUid-540906"&gt;&lt;DIV class="lia-panel-message-content"&gt;&lt;DIV class="lia-decoration-border"&gt;&lt;DIV class="lia-decoration-border-content"&gt;&lt;DIV class="lia-quilt lia-quilt-forum-message lia-quilt-layout-forum-message"&gt;&lt;DIV class="lia-quilt-row lia-quilt-row-forum-message-main"&gt;&lt;DIV class="lia-quilt-column lia-quilt-column-20 lia-quilt-column-right lia-quilt-column-main-right"&gt;&lt;DIV class="lia-quilt-column-alley lia-quilt-column-alley-right"&gt;&lt;DIV class="lia-message-body"&gt;&lt;DIV class="lia-message-body-content"&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a CSV file with a variable for longitude and another variable for latitude for over 20 000 observations.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to convert these coordinates into geohash by creating a new variable in SAS.&lt;/P&gt;&lt;P&gt;The end goal is to merge this data set with another one based with the identifier variable geohash.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone know how to do this?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance for your help&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
    <pubDate>Wed, 06 Mar 2019 21:21:24 GMT</pubDate>
    <dc:creator>Dublin187</dc:creator>
    <dc:date>2019-03-06T21:21:24Z</dc:date>
    <item>
      <title>how to convert a longitude and latitude coordinates into geohash in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-convert-a-longitude-and-latitude-coordinates-into-geohash/m-p/540931#M149284</link>
      <description>&lt;DIV class="lia-component-thread-subject"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="lia-component-message-list"&gt;&lt;DIV class="linear-message-list message-list"&gt;&lt;DIV class="lia-linear-display-message-view"&gt;&lt;DIV class="first-message"&gt;&lt;DIV class="lia-message-view message-uid-540906"&gt;&lt;DIV class=""&gt;&lt;DIV class="lia-js-resize-images lia-component-forums-widget-board-message-view"&gt;&lt;DIV&gt;&lt;DIV class="lia-panel-message-root lia-message-board lia-panel-message lia-js-data-messageUid-540906"&gt;&lt;DIV class="lia-panel-message-content"&gt;&lt;DIV class="lia-decoration-border"&gt;&lt;DIV class="lia-decoration-border-content"&gt;&lt;DIV class="lia-quilt lia-quilt-forum-message lia-quilt-layout-forum-message"&gt;&lt;DIV class="lia-quilt-row lia-quilt-row-forum-message-main"&gt;&lt;DIV class="lia-quilt-column lia-quilt-column-20 lia-quilt-column-right lia-quilt-column-main-right"&gt;&lt;DIV class="lia-quilt-column-alley lia-quilt-column-alley-right"&gt;&lt;DIV class="lia-message-body"&gt;&lt;DIV class="lia-message-body-content"&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a CSV file with a variable for longitude and another variable for latitude for over 20 000 observations.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to convert these coordinates into geohash by creating a new variable in SAS.&lt;/P&gt;&lt;P&gt;The end goal is to merge this data set with another one based with the identifier variable geohash.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone know how to do this?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance for your help&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 06 Mar 2019 21:21:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-convert-a-longitude-and-latitude-coordinates-into-geohash/m-p/540931#M149284</guid>
      <dc:creator>Dublin187</dc:creator>
      <dc:date>2019-03-06T21:21:24Z</dc:date>
    </item>
    <item>
      <title>Re: how to convert a longitude and latitude coordinates into geohash in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-convert-a-longitude-and-latitude-coordinates-into-geohash/m-p/541017#M149314</link>
      <description>&lt;P&gt;I could not find the routine for calculating geohashes. But you can get the result from geohash.org, e.g.:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have; /* just som random test data */
  input latitude longitude;
cards;
45.63 114.67
18.876 11.44
;run;

filename geohash url;
data want;
  set have;
  fname=cats('http://geohash.org/?q=',latitude,',',longitude,'&amp;amp;format=url&amp;amp;redirect=0');
  infile geohash url filevar=fname truncover;
  input url $40.;  /* the result is like &lt;SPAN style="display: inline !important; float: none; background-color: transparent; color: #000000; font-family: Consolas; font-size: 13.33px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: pre-wrap; word-spacing: 0px; word-wrap: break-word;"&gt;http://geohash.org/c216ne&lt;/SPAN&gt; */
  geohash=scan(url,-1,'/');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 Mar 2019 09:01:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-convert-a-longitude-and-latitude-coordinates-into-geohash/m-p/541017#M149314</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2019-03-07T09:01:54Z</dc:date>
    </item>
    <item>
      <title>Re: how to convert a longitude and latitude coordinates into geohash in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-convert-a-longitude-and-latitude-coordinates-into-geohash/m-p/541222#M149397</link>
      <description>&lt;P&gt;I replicated the logic shown in Wikipedia to transform a geohash into coordinates.&lt;/P&gt;
&lt;P&gt;You can write the reverse operation.&lt;/P&gt;
&lt;P&gt;You can do this in a macro or use proc fcmp to make it easier to call.&lt;/P&gt;
&lt;P&gt;Does this help?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  GEOMAP_CHAR='ezs42';
  length GEOMAP_BIN LAT_BIN LON_BIN $50;
  do I=1 to length(GEOMAP_CHAR);
    VAL_DEC=index('0123456789bcdefghjkmnpqrstuvwxyz',char(GEOMAP_CHAR,I))-1;
    VAL_BIN=put(VAL_DEC,binary5.);     
    GEOMAP_BIN=catt(GEOMAP_BIN,VAL_BIN);      
  end;     
  do I=1 to length(GEOMAP_BIN);
    if mod(I,2)=0 then LAT_BIN=catt(LAT_BIN,char(GEOMAP_BIN,I));      
    else               LON_BIN=catt(LON_BIN,char(GEOMAP_BIN,I));      
  end;          
  do I=1 to length(LAT_BIN);
    SPAN=180/2**I;
    INC=ifn(char(LAT_BIN,I)='1',1,-1);
    LAT_INC=SPAN/2*INC;
    LAT+LAT_INC;       
  end;
  do I=1 to length(LON_BIN);
    SPAN=360/2**I;
    INC=ifn(char(LON_BIN,I)='1',1,-1);
    LON_INC=SPAN/2*INC;
    LON+LON_INC;       
  end;          
  putlog LAT= LON=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;LAT=42.604980469 LON=-5.603027344&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Mar 2019 20:54:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-convert-a-longitude-and-latitude-coordinates-into-geohash/m-p/541222#M149397</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-03-07T20:54:50Z</dc:date>
    </item>
    <item>
      <title>Re: how to convert a longitude and latitude coordinates into geohash in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-convert-a-longitude-and-latitude-coordinates-into-geohash/m-p/541225#M149398</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Thank you for your suggestion. I am only a beginner in coding so writing the reverse operation of this code would very challenging for me.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can this translation program be applied for a longitude and latitude variables? or do I have to input the data individually?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Mar 2019 21:07:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-convert-a-longitude-and-latitude-coordinates-into-geohash/m-p/541225#M149398</guid>
      <dc:creator>Dublin187</dc:creator>
      <dc:date>2019-03-07T21:07:50Z</dc:date>
    </item>
    <item>
      <title>Re: how to convert a longitude and latitude coordinates into geohash in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-convert-a-longitude-and-latitude-coordinates-into-geohash/m-p/541249#M149403</link>
      <description>&lt;P&gt;This does the reverse translation:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data HAVE;
  LAT=42.604980469 ;
  LON=-5.603027344 ;
run;
data WANT;
  set HAVE;
  keep  GEOMAP_CHAR;
  GEOMAP_LEN=5;   
  length GEOMAP_CHAR $5 GEOMAP_BIN LAT_BIN LON_BIN $50;

  LOW=-180;
  do I=1 to ceil(GEOMAP_LEN*5/2+1);
    SPAN   = 360/2**I;  
    CENTER = LOW+SPAN; 
    INC    = (LON &amp;gt; CENTER);
    LOW    = LOW+SPAN*INC;               
    LON_BIN= catt(LON_BIN,INC);       
  end;          
  LOW=-90;
  do I=1 to ceil(GEOMAP_LEN*5/2);
    SPAN   = 180/2**I;  
    CENTER = LOW+SPAN; 
    INC    = (LAT &amp;gt; CENTER);
    LOW    = LOW+SPAN*INC;               
    LAT_BIN= catt(LAT_BIN,INC);       
  end;        
  do I=1 to ceil(GEOMAP_LEN*5/2);
    GEOMAP_BIN=catt(GEOMAP_BIN,char(LON_BIN,I));       
    GEOMAP_BIN=catt(GEOMAP_BIN,char(LAT_BIN,I));      
  end;          
  do I=1 to GEOMAP_LEN*5 by 5;  
    VAL_BIN=substr(GEOMAP_BIN,I,I+5);
    VAL_DEC=input(VAL_BIN,binary5.);
    VAL_CHAR=char('0123456789bcdefghjkmnpqrstuvwxyz',VAL_DEC+1); 
    GEOMAP_CHAR=catt(GEOMAP_CHAR,VAL_CHAR);
  end;
  putlog GEOMAP_CHAR=;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;GEOMAP_CHAR=ezs42&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Mar 2019 22:04:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-convert-a-longitude-and-latitude-coordinates-into-geohash/m-p/541249#M149403</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-03-07T22:04:04Z</dc:date>
    </item>
  </channel>
</rss>

