GEOCODE Procedure

Example 3: U.S. City Geocoding

Features:

CITY geocoding method

Procedure Options:
METHOD=
DATA=
OUT=
Other features:
Base SAS functions:
SAS DATA step
PRINT procedure
Data set: mapsgfk.uscity_all (lookup data set)
Sample library member: GEOCITY
This example illustrates the CITY geocoding method to obtain coordinates based on a United States city and state.
There is no need to use the ADDRESSCOUNTRYVAR= option because all of the cities to be geocoded are located in the United States. The LOOKUPCITY= option is absent, which indicates that no alternate lookup data set is specified. In these circumstances, starting with the second maintenance release of SAS 9.3, the GEOCODE procedure uses the default MAPSGFK.USCITY_ALL lookup data set.

Output

The following output from the PRINT procedure shows the output data set after running the GEOCODE procedure.
The output data set contains the LAT and LONG variables from the default lookup data set (MAPSGFK.USCITY_ALL).
The GEOCODED_TRAINING Output Data Set
The GEOCODED_TRAINING Output Data Set

Program

data training (label='Selected SAS training locations in USA');
  infile datalines dlm=',';
  length city  $ 24 
         state $ 2;
  input city   /* City name                 */
        state; /* Two-character postal code */
datalines;
Atlanta, GA
Bedminster, NJ
Cary, NC
Chicago, IL
Dayton, OH
Des Moines, IA
Detroit, MI
Hartford, CT
Miami, FL
Middleton, MA
Minneapolis, MN
New York, NY
Overland Park, KS
Philadelphia, PA
Phoenix, AZ
San Antonio, TX
San Francisco, CA
Seattle, WA
;
run;
proc geocode       
  method=city               /* Specify geocoding method          */
  data=training             /* Input data set of cities          */
  out=geocoded_training;    /* Output data set with LONG, LAT values  */
run;
proc print data=geocoded_training noobs;
run;
quit;

Program Description

Generate the TRAINING input data set that the GEOCODE procedure will use.
data training (label='Selected SAS training locations in USA');
  infile datalines dlm=',';
  length city  $ 24 
         state $ 2;
  input city   /* City name                 */
        state; /* Two-character postal code */
datalines;
Atlanta, GA
Bedminster, NJ
Cary, NC
Chicago, IL
Dayton, OH
Des Moines, IA
Detroit, MI
Hartford, CT
Miami, FL
Middleton, MA
Minneapolis, MN
New York, NY
Overland Park, KS
Philadelphia, PA
Phoenix, AZ
San Antonio, TX
San Francisco, CA
Seattle, WA
;
run;
Run the GEOCODE procedure with the generated TRAINING input data set.Specify the CITY method to add the latitude and longitude geographic coordinate values from the lookup data set to the addresses in the input data set. Those values are output to the GEOCODED_TRAINING data set. The default lookup data set is MAPSGFK.USCITY_ALL.
proc geocode       
  method=city               /* Specify geocoding method          */
  data=training             /* Input data set of cities          */
  out=geocoded_training;    /* Output data set with LONG, LAT values  */
run;
Print the entire GEOCODED_TRAINING output data set, suppressing the observation column.
proc print data=geocoded_training noobs;
run;
quit;