Handy-Dandy SAS® Functions, Part 2 of 3: The zipcitydistance Function

This Tech Tip was provided by Onecia Gibson, Research and Analysis Director Assistant, Office of Institutional Research, University of Kentucky.
 

This second part of the three-part series on Handy-Dandy SAS® Functions presents the use of the zipcitydistance function available in SAS® releases 9.2 and following.

At times, our university administrators want to know the distance between the institution and the hometowns of our students. Prior to the release of SAS 9.2®, finding the distance between two cities involved coding a trigonometrically based formula for calculating distance between two points identified by latitude and longitude1. In the 9.2 release, SAS® introduced the zipcitydistance function that calculates the geodetic distance between two cities using zip codes2.

Suppose the following database contains a list of University of Kentucky students with their hometown zip codes, and we need to know how far each student is from home.

sas 1.jpg

The following code calculates the distance for each student in the input database “cohort.”

sas 2.jpg

The resulting database is:

sas 3.jpg

References:

1 Usage Note 5325: Calculating the distance between ZIP codes. (2009). Retrieved April 16, 2012, from the SAS website.

2 Usage Note 36091: New function ZIPCITYDISTANCE available in SAS® 9.2 to calculate the geodetic distance between two ZIP code locations. (2009). Retrieved April 16, 2012, from the SAS website.


 

 Comments:

 
To add a comment, Sign In
Total Comments: 3
 
Gary posted on 8/22/2012 12:36 PM
Great tip! After reading it, I followed the link and discovered that SAS updates and distributes a zip code reference list in transport file format. I don't believe you even need a SAS license to download it, and that's something that usually has a price tag attached to it. Get it here: http://support.sas.com/rnd/datavisualization/mapsonline/html/misc.html\
After downloading, I just save it to .csv and used it in another data analysis environment, even though I do have a SAS license. The longitude/latitude data also makes it very useful for creating maps.
Julianna posted on 8/24/2012 10:43 AM
Keep the tips coming, Onecia (AND AIR); I find these very helpful.
Stephen posted on 11/12/2012 10:08 AM
You may have a problem accessing the referenced source because of the backslash at the end of the provided link. But deleting the backslash correctly opens the source page.