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
- /
- Base SAS Programming
- /
- Lat/Long

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
- Highlight
- Email to a Friend
- Report Inappropriate Content

06-13-2011 09:31 PM

I've a table that looks like this..

Store # Zip Code Lat # Long #

A1 12223

B2 45677

B3 12345

B4 12234

A3 67543

Using Lat / Long of a location getting the proxmity of each location for example store A1 is 2 miles from the nearest next store and store B2 is 4 miles to the nearest next store.... Thank You again for your assitance

Store # Zip Code Lat # Long #

A1 12223

B2 45677

B3 12345

B4 12234

A3 67543

Using Lat / Long of a location getting the proxmity of each location for example store A1 is 2 miles from the nearest next store and store B2 is 4 miles to the nearest next store.... Thank You again for your assitance

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

06-13-2011 11:14 PM

I would approach this with PROC SQL to obtain a Cartesian product of the Store ZIP code data with itself. That would yield a table with

store ZIP store2 ZIP2

as columns. Then you could use the ZIPCITYDISTANCE function to compute the distance between two ZIPs. Something like.

*untested code;

PROC SQL;

CREATE TABLE both AS

SELECT a.store, a.ZIP,

b.store AS store2,

b.zip AS ZIP2,

ZIPCITYDISTANCE(a.zip, b.zip) AS Distance

FROM a,b;

QUIT; RUN;

Be sure to download the latest version of SASHELP.ZIPCODE (see the SAS manual for the function).

store ZIP store2 ZIP2

as columns. Then you could use the ZIPCITYDISTANCE function to compute the distance between two ZIPs. Something like.

*untested code;

PROC SQL;

CREATE TABLE both AS

SELECT a.store, a.ZIP,

b.store AS store2,

b.zip AS ZIP2,

ZIPCITYDISTANCE(a.zip, b.zip) AS Distance

FROM a,b;

QUIT; RUN;

Be sure to download the latest version of SASHELP.ZIPCODE (see the SAS manual for the function).

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

06-14-2011 01:24 PM

The function GEODIST returns the geodetic distance between two latitude and longitude coordinates. So Doc's code could be modified to use that function and

GEODIST(A.lat, A.long, B.lat,b.long,'M') as Distance.

GEODIST(A.lat, A.long, B.lat,b.long,'M') as Distance.

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

06-14-2011 08:30 PM

I have version 9.1 SAS loaded in my desktop when I ran the code it error out " It stated the zipcitydistance function didn't exist. I read on the net that its new for 9.2 if that is the case what can I use to tweak it? I will try the GeoDist... Thank you again for your assitance... What I would like the code to provide in miles is the nearest store... for example store 1 is 3 miles from store 3 and store 2 is 5 miles from store 1 ... Again thanks