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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 899 views
  • 0 likes
  • 3 in conversation