Write and run SAS programs in your web browser

Finding minimum distance between a set of coordinates

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 9
Accepted Solution

Finding minimum distance between a set of coordinates

Hi,

I have a dataset like this:

LatLong
51.39824-0.09366
51.52927-0.04583
51.541820.038004
51.41895-0.30561
51.59302-0.06998
51.60087-0.19474
51.55101-0.13727
51.50019-0.07006
51.48329-0.02586

I need to determine the minimum distance between these set of coordinates. I know about a function geodist() to determine distance between 2 coordinates, but not sure how to loop over through this set from the table.

 

Greatly appreciate your help.

Thanks!


Accepted Solutions
Solution
‎07-31-2016 05:47 PM
Grand Advisor
Posts: 16,300

Re: Finding minimum distance between a set of coordinates

You have to check distance between all unfortunately. 

Use a Cartesian join in SQL and the GEODIST() function. 

 

Heres a sketch of the code. 

 

 

Proc SQL;

Create table dist as

Select a.*,
            B.lat as lat2,
            B.long as long2,
            Geodist(....) as distance
From have as a
CROSS JOIN 
have as b
Order by distance;
Quit;

View solution in original post


All Replies
Esteemed Advisor
Posts: 5,068

Re: Finding minimum distance between a set of coordinates

Try the min() aggregate function in SQL, or PROC SUMMARY using the outcome oD geodist() as input.
Data never sleeps
Solution
‎07-31-2016 05:47 PM
Grand Advisor
Posts: 16,300

Re: Finding minimum distance between a set of coordinates

You have to check distance between all unfortunately. 

Use a Cartesian join in SQL and the GEODIST() function. 

 

Heres a sketch of the code. 

 

 

Proc SQL;

Create table dist as

Select a.*,
            B.lat as lat2,
            B.long as long2,
            Geodist(....) as distance
From have as a
CROSS JOIN 
have as b
Order by distance;
Quit;
Occasional Contributor
Posts: 9

Re: Finding minimum distance between a set of coordinates

Thanks a lot Reeza. It worked!

Smiley Happy

-Sanchit

Post a Question
Discussion Stats
  • 3 replies
  • 217 views
  • 3 likes
  • 3 in conversation