GEOCODE Procedure

Example 5: ZIP+4 Geocoding


PLUS4 geocoding method

Procedure Options:
Other features:
Base SAS functions:
PRINT procedure
Data set: lookup.zip4 (from SAS MapsOnline)
Sample library member: GEOZIP4
This example illustrates the PLUS4 geocoding method using US Postal Service ZIP and ZIP+4 postal codes. Lookup data can be downloaded from SAS MapsOnline ( You can also purchase from Melissa Data the GEO*Data product containing ZIP+4 centroids (


The following output from the PRINT procedure shows the GEOCODED_CUSTOMERS output data set after running the GEOCODE procedure.
The example output shows four results for the customer names and addresses submitted as input. These include the location coordinates (X, Y), the matching observation’s (row) number from the lookup data set (M_OBS), and the method with which GEOCODE made the match.
The _MATCHED_ column value in the output data set indicates how each address was located:
ZIP+4    - The ZIP and ZIP+4 values were matched. The location is the 
center of the street segment. 
ZIP mean - The ZIP+4 value was not matched and the GEOCODE procedure used 
the ZIP method where multiple ZIP code matches were averaged.
ZIP      - The ZIP+4 value was not matched and the GEOCODE procedure used 
the ZIP method where a single ZIP code match was found.
City     - Neither the ZIP+4 nor the ZIP code were found but the CITY 
method returned a match.
The GEOCODED_CUSTOMERS Output Data Set with PLUS4 Method Variables
The GEOCODED_CUSTOMERS Output Data Set with PLUS4 Method Variables
The LIBNAME statement assigns the library name LOOKUP to the location where the ZIP+4 lookup data is installed. You must edit the ’pathname’ in the following LIBNAME statement to reference the lookup data location on your system.
libname lookup 'pathname';
Generate the CUSTOMERS input data set of names and addresses that the GEOCODE procedure will use.
data customers;
   infile datalines dlm=',';
   length name city $32 state $2;
   input name      /* Customer name      */
         zip       /* Customer ZIP Code  */
         plus4     /* ZIP+4              */
         city      /* City name          */
         state;    /* State abbreviation */
J. Cheever Loophole, 27603, 2681, Raleigh, NC
Cuthbert J. Twillie, 77450, 3418, Katy, TX
Kaspar Gutman, 19808, 1927, Wilmington, DE
Dr. Hugo Z. Hackenbush, 19363, 1735, Oxford, PA
Charlie Allnut, 28365, 2277, Mount Olive, NC
Larson E. Whipsnade, 19963, 1941, Milford, DE
Guillermo Ugarte, ., 2208, Bradenton, FL
Capt. Geoffrey Spaulding, 19975, 7504, Selbyville, DE
Joel Cairo, 19944, 4401, Fenwick Island, DE
Charles Blutoski, 19953, 3141, Hartly, DE
Rufus T. Firefly, ., ., Wimberley, TX
Otis B. Driftwood, 19955, 53, Kenton, ,
Gordon Miller, 21921, 5335, Elkton, MD
Run the GEOCODE procedure with the generated CUSTOMERS input data set. Specify that GEOCODE use the PLUS4 method to look up each address.
proc geocode           /* Invoke geocoding procedure  */
     method=plus4             /* Specify geocoding method    */
     lookup=lookup.zip4       /* Lookup data from MapsOnline */
     data=customers           /* Input data set to geocode   */
     out=geocoded_customers;  /* Specifu name of Output data set of locations */
Print the entire GEOCODED_CUSTOMERS output data set, suppressing the observation column.
proc print data=geocoded_customers noobs;