Hello SAS experts,
I encountered 3 quick questions regarding distance/travel time between two zip codes.
1. zipcitydistance is helpful to calculate the distances between two groups easily. However, I didn't find the code that could give me the travel time.
Is there a convenient way to calculate the travel time between two zip codes?
2. Is there a limit sample to calculate the distance of two zip codes?
I got some error like below when running big datasets.
WARNING: Limit set by ERRORS= option reached. Further errors of this type will not be printed.
NOTE: The DATA step has been abnormally terminated.
NOTE: Mathematical operations could not be performed at the following places. The results of the operations have been set to missing values.
3. Why the results of the distance is different than I put the zip code in other website individually?
data have; input HQ_ZIP AFF_ZIP; datalines; 10001 90001 98101 32789 ; run; data want; set have; distance = zipcitydistance(HQ_ZIP, AFF_ZIP); run;
You can see the distance between zip 10001 and zip 9001 is 2454.1.
But if I put those zip codes to this website, https://www.zipcodesoft.com/distance-between-zip-codes
I got something like close to 2448.
I don't know which to follow.
Is there a simple way to calculate road distance of the two zip codes?
Many thanks!
@chimei0403 wrote:
Hello SAS experts,
I encountered 3 quick questions regarding distance/travel time between two zip codes.
1. zipcitydistance is helpful to calculate the distances between two groups easily. However, I didn't find the code that could give me the travel time.
Is there a convenient way to calculate the travel time between two zip codes?
2. Is there a limit sample to calculate the distance of two zip codes?
I got some error like below when running big datasets.
WARNING: Limit set by ERRORS= option reached. Further errors of this type will not be printed.
NOTE: The DATA step has been abnormally terminated.
NOTE: Mathematical operations could not be performed at the following places. The results of the operations have been set to missing values.
3. Why the results of the distance is different than I put the zip code in other website individually?
If you are getting errors from the ZIPCITYDISTANCE function it means that either one, or both, Zip codes is missing or invalid.
For this function Zip+4 codes are "invalid" because the Sashelp.zipcode data set does not have centroids for the +4 versions.
This is clear with this example:
225 data example; 226 x1= zipcitydistance('83701','83704'); 227 x2= zipcitydistance('83701','83704-1069'); 228 run; NOTE: Invalid argument to function ZIPCITYDISTANCE('83701','83704-1069') at line 227 column 8. x1=1.3 x2=. _ERROR_=1 _N_=1
If you have real data like I get then Zip codes can have too many digits, missing digits, typos reversing digits which often are invalid but not always, or characters other than digits.
If your errors do not include ZIPCITYDISTANCE then you need to provide the entire log from your code. Copy the text from the log, open a text box on the forum using the </> icon that appears above the message window and paste in the box. It should look like my example above.
Do note that the documentation for the function states:
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.
using this definition for Geodetic:
the shortest line that can be drawn between two points on the elipsoidal surface of the earth; a curve drawn on any given surface so that the osculating plane of the curve at every point shall contain the normal to the surface; the minimum line that can be drawn on any surface between any two points.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.