ZIPCITYDISTANCE Function

Returns the geodetic distance between two ZIP code locations.

Categories: Distance
State and ZIP Code

Syntax

ZIPCITYDISTANCE(zip-code-1, zip-code-2)

Required Argument

zip-code

specifies a numeric or character expression that contains the ZIP code of a location in the United States of America.

Details

The ZIPCITYDISTANCE function returns the geodetic distance in miles between two ZIP code locations. The centroid of each ZIP code is used in the calculation.
The SASHELP.ZIPCODE data set must be present when you use this function. If you remove the data set, then ZIPCITYDISTANCE will return unexpected results.
The SASHELP.ZIPCODE data set contains postal code information that is used with ZIPCITYDISTANCE and other ZIP code functions. To determine when this data set was last updated, execute PROC CONTENTS:
proc contents data=SASHELP.ZIPCODE;
run;
Output from the CONTENTS procedure provides the date of the last update, along with the contents of the SASHELP.ZIPCODE data set.
Note: You can download the latest version of the SASHELP.ZIPCODE file from the SAS external Web site. The file is located at the Technical Support Web site. Select Zipcode Dataset from the Name column to begin the download process. You must execute the CIMPORT procedure after you download and unzip the data set.

Example

In the following example, the first ZIP code identifies a location in San Francisco, CA, and the second ZIP code identifies a location in Bangor, ME. ZIPCITYDISTANCE returns the distance in miles between these two locations.
data _null_;
   distance=zipcitydistance('94103', '04401');
   put 'Distance from San Francisco, CA, to Bangor, ME: ' distance 4. ' miles';
run;
SAS writes the following output to the log:
Distance from San Francisco, CA, to Bangor, ME: 2782 miles

See Also

Functions: