Batch Geocoding Example

Example Code

The following example uses the batch geocoding macro to geocode an address data set using a copy of the MAPS.WAKE.TRACT map supplied with SAS/GIS software. That map was originally created by importing the U.S. Census Bureau TIGER files for Wake County, North Carolina. This example uses a copy in the WORK library rather than the original in the MAPS library to show how the geocoded addresses can be imported and appended to the spatial data.
/*--- Copy the base map to the WORK library ---*/
proc gis;
   copy MAPS.WAKE.TRACT.GISMAP / /* Map entry to copy */
           destlib = WORK        /* Destination library */
           destcat = WORK.WAKE   /* Destination catalog */
           sel     = (_all_)     /* Copy all map components */
           blank                 /* Clear internal map path */
           replace;              /* Overwrite existing entry */
quit;

/*--- Create the address data set to geocode ---*/
data WORK.ADDRESSES (label='Data set to geocode');
   input address  $ 1-23    /* Street address */
         resident $ 24-48   /* Person at the location */
         zip      $ 49-53   /* 5-digit US postal code */
         city     $ 55-69   /* City name */
         state    $ 70-71;  /* US state name */
cards;
700  Madison Avenue    Patricia Smith           27513 Cary
506  Reedy Creek Road  Jean Francois Dumas      27513 Cary
1106 Medlin Drive      Michael Garriss          27511                NC
1150 Maynard Road      Kaspar Gutman            27511 Cary
138  Dry Ave.          Susan Lang               27511                NC
3112 Banks Road        Roy Hobbs                27603 Raleigh        NC
305  Mill Creek Drive  Alan Picard              27526 Fuquay-Varina  NC
1998 S. Main St.       Guillermo Ugarte               Wake Forest
7825 Old Middlesex Rd  Capt. Jeffrey Spaulding  27807 Bailey         NC
5550 Old Stage Road    Emily Joyner             27603 Raleigh        NC
3212 Avent Ferry Road  Fred C. Dobbs            27540                NC
1050 King Charles Rd.  Karin Schmidt                . Raleigh        NC
6819 Buffaloe Road     Ferdinand Paulin         27604                NC
3211 Constant Circle   Gordon Miller            34121
6111 Old Faison Road   Alan Picard              27545 Knightdale
725  N. Raleigh Street Evan Rudde               27501 Angier         NC
;
run;

/*--- Set up variables for the Batch Geocoding program ---*/
%gcbatch( glib  = WORK,             /* Geocoding library */
          geod  = WORK.ADDRESSES,   /* Address data to geocode */
          nv    = RESIDENT,         /* Who's at the address */
          av    = ADDRESS,          /* Address variable */
          cv    = CITY,             /* Place name */
          sv    = STATE,            /* State name */
          zv    = ZIP,              /* ZIP code (5-digit) */
          pv    = TRACT,            /* AREA value from map data */
          mname = WORK.WAKE.TRACT); /* Map data used for geocoding */

/*--- Run the Batch Geocoding program ---*/
dm 'af cat=SASHELP.GIS.GEOCODEB.SCL';

/*--- Show geocoding results on a bar chart -------------------*/
axis1     label=(height=1.3 'Address Status');
axis2     label=(angle=-90 rotate=90 height=1.3 'Percent');
title1    "Geocoding Results";
title2    "Wake County, NC";
footnote1 j=l "Geocoded by SAS/GIS";
proc gchart data=WORK.ADDRESSES;  /* Geocoded data set */
   vbar _status_ /                /* Midpoint (x-axis) variable */
           descending             /* Order of results */
           type    = pct          /* Response (y-axis) variable */
           outside = pct          /* Label on top of bars */
           inside  = freq         /* Label inside of bars */
           maxis   = axis1        /* x-axis */
           raxis   = axis2;       /* y-axis */
   run;
quit;

/*--- Set up Batch Import variables ---*/
%let imp_type = GENPOINT;       /* Importing data as points */
%let maplib   = WORK;           /* Map library */
%let mapcat   = WAKE;           /* Map catalog */
%let mapname  = TRACT;          /* Map catalog entry */
%let spalib   = WORK;           /* Spatial data library */
%let spaname  = WAKE;           /* Spatial entry name */
%let cathow   = UPDATE;         /* Append existing entry */
%let spahow   = APPEND;         /* Append to spatial data sets */
%let nidvars  = 0;              /* Put points in one layer */
%let infile   = WORK.ADDRESSES; /* Data set to import */

/*--- Run the Batch Import program ---*/
DM 'af cat=SASHELP.GISIMP.BATCH.SCL';

/*--- Modify imported layer and map with GIS Procedure ---*/
proc gis cat=WORK.WAKE;
   /*--- Set display parmameters for imported point layer */
   layer update ADDRESSES /                /* Geocoded layer */
      type    = point                      /* Layer type */
      where   = 'node=1'                   /* Layer definition */
      des     = 'Geocoded addresses'       /* Label for entry */
      default = (point=(color     = yellow /* Symbol color */
                        font      = marker /* Symbol font */
                        character = 'V'    /* Symbol to use */
                        size      = 10));  /* Symbol height */
   /*--- Set display parmameters for the map */
   map update TRACT /                      /* Map entry name */
      layerson = (TRACT ADDRESSES)         /* Turn on layers */
      cback    = gray                      /* Background color */
      legend   = hideall                   /* Turn off legend */
      des      = 'Wake County geocoding';  /* Label for entry */
   /*--- Add label in lower right corner of the map */
   maplabel create / 
      text      = 'Geocoding by SAS/GIS' /* Label text */
      map       = WORK.WAKE.TRACT        /* Map entry */
      attach_to = window                 /* Do not pan label */
      position  = (bottom right)         /* Window position */
      color     = cxA81010;              /* Text color */
   run;
quit;

/*--- Open map in SAS/GIS ---*/
dm 'gis map=WORK.WAKE.TRACT';

Example Results

The geocoded latitude and longitude values are written to the WORK.ADDRESSES input data set, along with the census tract values for each found address. The match results for each geocoded address are also written to that data set. A bar chart that summarizes the results of the geocoding process is generated using the GCHART procedure in SAS/GRAPH software.
When the import is complete, the map opens in SAS/GIS. The found locations are in the map's ADDRESSES point layer.
Note: The WHERE clause for the ADDRESSES point layer is WHERE='NODE=1', which displays points for all of the found addresses. You can modify the WHERE clause to show only those addresses that were matched with a higher degree of certainty (for example,.WHERE='_SCORE_>=40').
Note: For a more detailed example of batch geocoding, see the article “Cheap Geocoding: SAS/GIS and TIGER Data,” available in the Geocoding section of the Downloads page in the SAS Maps Online area at http://support.sas.com. The article is a reprint of a presentation from SUGI 30 and is also available in the proceedings for that conference.