Solved
Contributor
Posts: 28

# Help with Calculating the distance between points from map coordinates

Hi

I am undertaking a piece of work which is calculating the distance between customers and a centre. For this example I'm using our Birmingham centre but i'll be devising a macros that odes it for all centres so we can calculate which centre is nearest to everybody once I get it nailed down for one example.

I'm not using drive times or anything just using standard as the crow flies kind of distance as only looking for an estimate.

So first of all I downloaded a file of postcodes and the logitude and latitide from here   Download UK Postcodes with Latitude and Longitude

this is saved into a csv format and uploaded in my code. Then this page gave me the formula I wanted to use    3973 - Calculating the distance between points from map coordinates

I have verified the formula is correct using other sources.

My code is below. My full_details has basic customer information including their postcode. I first add the birmingham postcode as a column and extract the postcode outward from these to join to the downloaded postcode table

in order to get the co-ordinates so I can use the formula. I then use the formula given on the SAS help page.

In order to sense check results I use this link    Online Conversion - Great Circle Distance

However when I run this code (which all works fine except when the customer postcode is incorrect or missing in the data which isn't an issue) it gives me numbers which are way too high.

For example a customer in York should be 93 miles away according to the online calculator which looking at google maps is correct. But my code is giving me 2,690 miles. I cannot for the life of me see why this would be. I have attached the code which tries the calculation twice. one broke down into many small steps, one with it all in one go.

Can anyone else figure this out?

Thanks

Stephen

Accepted Solutions
Solution
‎07-23-2014 08:00 AM
Regular Contributor
Posts: 151

## Re: Help with Calculating the distance between points from map coordinates

Are you getting degrees and radians mixed up?  An easier way of calculating the distance is to use the GEODIST function, you just specify whether the coordinates are in degrees or radians and whether you want the output in miles or kilometres.

All Replies
Solution
‎07-23-2014 08:00 AM
Regular Contributor
Posts: 151

## Re: Help with Calculating the distance between points from map coordinates

Are you getting degrees and radians mixed up?  An easier way of calculating the distance is to use the GEODIST function, you just specify whether the coordinates are in degrees or radians and whether you want the output in miles or kilometres.

Contributor
Posts: 28

## Re: Help with Calculating the distance between points from map coordinates

yeah I forgot to convert the co-ordinates into radians. I will look into the GEODIST function as well. Thanks for the reply.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
• 2 replies
• 1427 views
• 0 likes
• 2 in conversation