## Lat/Long

Regular Contributor
Posts: 240

# Lat/Long

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
Posts: 2,125

## Re: Lat/Long

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;

Super User
Posts: 13,583

## Re: Lat/Long

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.
Regular Contributor
Posts: 240

## Re: Lat/Long

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
Discussion stats
• 3 replies
• 245 views
• 0 likes
• 3 in conversation