BookmarkSubscribeRSS Feed
BETO
Fluorite | Level 6
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
3 REPLIES 3
Doc_Duke
Rhodochrosite | Level 12
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).
ballardw
Super User
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.
BETO
Fluorite | Level 6
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

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 1108 views
  • 0 likes
  • 3 in conversation