turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- General Programming
- /
- Help with Calculating the distance between points ...

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

07-23-2014 06:52 AM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to troopon

07-23-2014 08:00 AM

All Replies

Solution

07-23-2014
08:00 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to troopon

07-23-2014 08:00 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to troopon

07-23-2014 08:31 AM

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