GEOCODE Procedure

Example 6: British Postcode Geocoding

Features:

ZIP geocoding method

Procedure Options:
METHOD=
DATA=
OUT=
LOOKUP=
ADDRESSZIPVAR=
LOOKUPZIPVAR=
LOOKUPLONGVAR=
LOOKUPLATVAR=
ATTRIBUTEVAR=
Other features:
Base SAS functions:
SAS DATA step
PRINT procedure
Data set: lookup.GBpostcodes (Postcode lookup data from MapsOnline)
Sample library member: GEOZIPUK
This example illustrates the ZIP geocoding method using British Royal Mail postcodes. Lookup data can be downloaded from SAS MapsOnline ( http://support.sas.com/rnd/datavisualization/mapsonline/html/downloads.html). See Non-U.S. Postcodes for details.

Output

The following output from the PRINT procedure shows the GEOCODED_OFFICES output data set after running the GEOCODE procedure.
The GEOCODED_OFFICES Output Data Set with ZIP Method Variables
The GEOCODED_OFFICES Output Data Set with ZIP Method Variables
The LIBNAME statement assigns the library name LOOKUP to the location where the GBpostcodes 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 OFFICES input data set of addresses that the GEOCODE procedure will use.Each variable is delimited by a comma. Maximum variable lengths are specified. An important step is to remove spaces and capitalize the postcode values.
data offices;
  infile datalines dlm=',';
  length name city $24 postcode $8 country $2; 
  input name                           /* Office name              */
        city                           /* Name of city             */
        postcode                       /* Royal Mail postcode      */
        country;                       /* Two-character country ID */
  postcode=upcase(compress(postcode)); /* Normalize postcodes      */
datalines;
Quay Plaza, Manchester, M50 3BA, UK
Wittington House, Buckinghamshire, SL7 2EB, UK
Tara House, Glasgow, G2 1HG, UK
New Broad Street, London, EC2M 1NH, UK
;
run;
Run the GEOCODE procedure with the generated OFFICES input data set located in the WORK folder.The GEOCODE procedure uses either the postcode or the city from each address in the input data to match observations in the lookup data set.
proc geocode                     /* Invoke geocoding procedure            */
   method=zip                    /* Specify geocoding method              */
   data=work.offices             /* Input data set of offices             */
   out=geocoded_offices          /* Output data set of locations          */
   lookup=lookup.GBpostcodes     /* Postcode lookup data from MapsOnline  */
   addresszipvar=postcode        /* Postcode variable in input data       */
   lookupzipvar=pc               /* Postcode variable in lookup data      */
   lookuplongvar=Lon_WGS84_DD    /* Longitude variable in lookup data     */
   lookuplatvar=Lat_WGS84_DD     /* Latitude variable in lookup data      */
   attributevar=(lat_wgs84_dms   /* Additional variables from lookup data */
                 lon_wgs84_dms); /* set to assign to geocoded locations   */
run;
Print the entire GEOCODED_OFFICES output data set, suppressing the observation column.
proc print data=geocoded_offices noobs;
run;
quit;