GEOCODE Procedure

Example 4: World City Geocoding

Features:

CITY geocoding method

Procedure options:
METHOD=
DATA=
OUT=
ADDRESSCITYVAR=
ADDRESSCOUNTRYVAR=
ADDRESSSTATEVAR=PROVINCE
ATTRIBUTEVAR=
Other features:
Base SAS functions:
SAS DATA step
PRINT procedure
Data set: MAPSGFK.WORLD_CITIES.
Sample library member: GEOWCITY
This example illustrates the CITY geocoding method to obtain coordinates of various international cities.

Output

The following output from the PRINT procedure shows the output data set after running the GEOCODE procedure.
The first two observations of the same city (Bella Vista, Argentina) illustrate how the variable named ADDRESSSTATEVAR is used. Note in the GEOCODED_CITIES output that the LAT and /LONG values for the first Bella Vista observation are missing. There are two cities named Bella Vista in Argentina, but they are in different provinces. The first observation in the input data has a missing value for the PROVINCE variable, so the GEOCODE procedure cannot determine which of the matching cities to select. The _MATCHED_ value of '2 cities' shows the number of cities that were found. The second Bella Vista observation has a definite match and contains valid LAT and LONG coordinate variable values from the lookup data set. The GEOCODE procedure uses the province name 'Corrientes' in the input data to determine which of the two matching cities in the lookup data set was wanted.
The GEOCODED_CITIES Output Data Set with CITY Method Variables
The GEOCODED_CITIES Output Data Set with CITY Method Variables
This example produces an output data set listing coordinates for various international cities. Because the LOOKUPCITY= data set option is omitted the GEOCODE procedure uses the default GfK GeoMarketing world lookup data set MAPSGFK.WORLD_CITIES. This data set is an abridged version of world cities. Download a more complete version (MAPSGFK.WORLD_CITIES_ALL) from SAS MapsOnline ( http://support.sas.com/rnd/datavisualization/mapsonline/html/downloads.html). The ADDRESSSTATEVAR=PROVINCE option is used to specify the input data set variable containing a city’s corresponding state, province, or district value.
Generate the CITIES input data set that the GEOCODE procedure will use.
data cities (label='International cities');
  infile datalines dlm=',';
  length city $32 province $24 countryID $3;
  input city        /* City name                    */
        province    /* State/province/district name */
        countryID;  /* Three-character country code */
datalines;
Bella Vista, , ARG
Bella Vista, Corrientes, ARG
Adelaide, , AUS
Quebec, Quebec, CAN
Shanghai, , CHN
Skanderborg, , DNK
Barcelona, , ESP
Tallinn, , EST
Glasgow, , GBR
Pune, , IND
Dublin, , IRL
Seoul, , KOR
Luxembourg, , LUX
Vilnius, , LTU
Garza Garcia, , MEX
Bratislava, , SVK
Stockholm, , SWE
Bangkok, , THA
Houston, Texas, USA
Johannesburg, , ZAF
;
run;
Run the GEOCODE procedure with the generated CITIES input data set. Specify that GEOCODE use the city method. When geocoding international cities, you are required to use the ADDRESSCOUNTRYVAR= option to indicate that the cities are not all within the United States. Because the LOOKUPCITY= data set option is omitted the GEOCODE procedure uses the default world lookup data set MAPSGFK.WORLD_CITIES. The procedure produces the GEOCODED_CITIES output data set. The output data set contains the LAT and LONG coordinate variables from the lookup data set.
proc geocode                    /* Invoke geocoding procedure            */ 
   method=city                         /* Specify geocoding method              */
   data=cities                         /* Input data set of cities              */
   out=geocoded_cities                 /* Output data set of locations          */
   addresscityvar=city                 /* City name                             */
   addresscountryvar=countryID         /* Required for international geocoding  */
   addressstatevar=province            /* Optional state/province/district name */
   attributevar=(isoname mapidname1);  /* Values to assign to geocoded cities   */
run;
Print the entire GEOCODED_CITIES output data set, suppressing the observation column.
proc print data=geocoded_cities noobs;
run;
quit;