Usage Note 5325: Calculating the distance between ZIP codes
To calculate the distance between two ZIP codes, you need to have the longitude and latitude values in radians for the ZIP codes. You can then use the Great Circle Distance Formula to calculate the distance in miles between the two pairs of values.
Assume that the longitude and latitude for the first ZIP code are LONG1 and LAT1, respectively, and the longitude and latitude for the second ZIP code are LONG2 and LAT2, respectively. The Great Circle Distance formula is as follows:
Dist = 3949.99 * arcos(sin(lat1) * sin(lat2) +
cos(lat1) * cos(lat2) *
cos(long1 - long2));
If your longitude and latitude values are in degrees, you can use the following formula to first convert the degrees to radians:
long = atan(1)/45 * longdeg;
lat = atan(1)/45 * latdeg;
LONGDEG is the longitude in degrees and LATDEG is the latitude in degrees. If the longitude or latitude is stored in degrees/minutes/seconds, use the following equation to calculate decimal degrees before converting to radians:
VALUE = (degrees) + (minutes/60) + (seconds/3600);
If you do not have the longitude and latitude values for your ZIP codes, you should be able to find their values in the SASHELP.ZIPCODE data set. If you do not have this data set, it is available for download from the Maps Online Facility.
The ZIPCODE file contains a CPORT file of the SASHELP.ZIPCODE data set. You can run code similar to the following to take the file out of transport format and store it in the SASUSER library or other SAS data library to which you have write access:
proc cimport file="directory\zipcode.cpt" lib=sasuser;
run;
You can then extract the longitude and latitude values for your ZIP codes from this data set. Please note that the longitude and latitude values in the SASHELP.ZIPCODE data set are stored in decimal degrees.
Also, the new ZIPCITYDISTANCE function is available beginning with SAS 9.2. Please see Usage Note 36091
for information about the new function.
Operating System and Release Information
SAS System | SAS/GRAPH | Solaris | 8 TS M0 | |
OpenVMS VAX | 8 TS M0 | |
Microsoft Windows 95/98 | 8 TS M0 | |
64-bit Enabled Solaris | 8 TS M0 | |
HP-UX | 8 TS M0 | |
z/OS | 8 TS M0 | |
OS/2 | 8 TS M0 | |
64-bit Enabled HP-UX | 8 TS M0 | |
64-bit Enabled AIX | 8 TS M0 | |
OpenVMS Alpha | 8 TS M0 | |
Microsoft Windows NT Workstation | 8 TS M0 | |
CMS | 8 TS M0 | |
Tru64 UNIX | 8 TS M0 | |
AIX | 8 TS M0 | |
*
For software releases that are not yet generally available, the Fixed
Release is the software release in which the problem is planned to be
fixed.
How to calculate the distance between ZIP codes.
Type: | Usage Note |
Priority: | |
Topic: | SAS Reference ==> Procedures ==> GMAP
|
Date Modified: | 2009-06-04 15:33:06 |
Date Created: | 2001-06-28 10:52:22 |