Example 1: Batch Importing TIGER/Line Shapefiles (2007 – Present)
This example imports the downloaded, unzipped TIGER/Line shapefiles in the TIGERPATH location. These files represent the geographical area for the state of Delaware.
To run this example, first download the zipped Delaware shapefiles from the U.S.
Census Bureau, and then unzip them into the TIGERPATH folder. To reuse this sample code for other regions, you must change the paths defined in the macro variables to match your file locations and operating system. You must also change the names of the GIS catalog, entries, and data sets to describe the map region to be imported.
/* Specify folder containing unzipped Delaware shapefiles. */
%let TIGERPATH=C:\Public\Import TIGER\Shapefiles;
/* Specify the library to output the GIS catalog. */
%let MAPLIB=SASUSER;
/* Specify the catalog name for the GIS map and layer entries. */
%let MAPCAT=DELAWARE;
/* Specify the name of the GIS map entry. */
%let MAPNAME=COUNTIES;
/* Specify the library to output the GIS spatial data sets. */
%let SPATIALDATALIB=SASUSER;
/* Specify the base name for the GIS spatial data sets. */
%let SPATIALNAME=DELAWARE_;
/* Compile the TIGER/Line shapefile import program. */
FILENAME TIGER CATALOG 'SASHELP.GISIMP.TIGER2GIS.SOURCE';
%INCLUDE TIGER / SOURCE2;
/* Invoke the macro program to import the Delaware shapefiles. */
%TIGER2GIS
When the import completes, you can open the map named
SASUSER.DELAWARE.COUNTIES. This map displays the following information for Delaware: counties, streets, railways, waterways, census tracts, block groups and blocks, city boundaries, and ZCTAs (ZIP Code Tabulation Areas).
Note: The macro import program TIGER2GIS is stored in the catalog entry
SASHELP.GISIMP.TIGER2GIS.SOURCE. If there are any updates to that macro program, the updates will be available from the GEOCODING download section of SAS MapsOnline.
Example 2: Batch Importing TIGER Files (1990 – 2006)
This example imports the data for Wake County, North Carolina, from a 2006 Second Edition TIGER file. The example also appends from a separate TIGER file the data for neighboring Durham County, North Carolina.
/* Define the input parameters for Wake County, North Carolina. */
/* Define the import type. */
%let IMP_TYPE = TIGER;
/* Specify the complete path to the TIGER files for Wake County which were downloaded and unzipped using the required TIGER1 and TIGER2 filerefs. */
filename TIGER1 'tgr37183.rt1';
filename TIGER2 'tgr37183.rt2';
/* Define the output parameters for Wake County, North Carolina. */
%let MAPLIB = SASUSER;
%let MAPCAT = TIGER;
%let MAPNAME = COUNTIES;
%let CATHOW = CREATE;
%let SPALIB = SASUSER;
%let SPANAME = COUNTIES;
%let SPAHOW = CREATE;
/* Initiate the batch import by executing the SCL entry. */
DM 'AF C=SASHELP.GISIMP.BATCH.SCL';
/* Define the input parameters for Durham County, North Carolina. */
/* IMP_TYPE value stays the same, so you just need to reallocate the filerefs to point to the spatial data that was downloaded and unzipped for Durham County. */
filename TIGER1 'tgr37063.rt1';
filename TIGER2 'tgr37063.rt2';
Examples of Batch Importing 53
/* Define the output parameters for Durham County, North Carolina. */
/* The locations will stay the same, so you only need to redefine CATHOW and SPAHOW to update the catalog entries and append the spatial data sets for the second import. */
%let CATHOW = UPDATE;
%let SPAHOW = APPEND;
/* Initiate the batch import by executing the SCL entry a second time; this time to add the Durham County data to the Wake County data. */
DM 'AF C=SASHELP.GISIMP.BATCH.SCL';
When the import completes, you can open the map named
SASUSER.TIGER.COUNTIES. This map displays Wake and Durham counties.
Example 3: Batch Importing SASGRAPH and GENPOINT Data
This example creates a map of North Carolina with the state and county boundaries and then adds points at city locations. The state and county boundaries are imported from the MAPS library by using the SASGRAPH import type, and the points are appended using the GENPOINT import type.
/* Construct the data sets to be imported into SAS/GIS. The North Carolina state and county boundaries are obtained from the MAPS.USCOUNTY data set and the North Carolina city locations are obtained from the MAPS.USCITY data set.
Both data sets are supplied with SAS/GRAPH software. */
/* Subset just the boundaries for the state of North Carolina. */
data sasuser.nc;
set maps.uscounty;
/* 37 is the FIPS code for North Carolina.*/
where state=37;
run;
/* Subset just the cities in North Carolina. */
data sasuser.nccities;
set maps.uscity;
/* 37 is the FIPS code for North Carolina. */
where state=37;
run;
/* Define the input parameters for the SASGRAPH import of the boundaries. */
/* Define the import type. */
%let IMP_TYPE = SASGRAPH;
/* Specify where map data set is located. */
%let INFILE=SASUSER.NC;
/* Specify the identification variables, in hierarchical order (largest polygon first). */
%let NIDVARS=2;
%let IDVAR1=STATE;
%let IDVAR2=COUNTY;
/* Define the output parameters for the boundaries. */
%let MAPLIB = SASUSER;
%let MAPCAT = NC;
%let MAPNAME = NC;
%let CATHOW = CREATE;
%let SPALIB = SASUSER;
%let SPANAME = NC;
%let SPAHOW = CREATE;
/* Initiate the batch import by executing the SCL entry. */
DM 'AF C=SASHELP.GISIMP.BATCH.SCL';
/* Define the input parameters for the batch import of the GENPOINT data set for the cities. */
/* The import type has changed, so redefine the IMP_TYPE macro variable. */
%let IMP_TYPE=GENPOINT;
/* Specify where the generic point data is located. */
%let INFILE=SASUSER.NCCITIES;
/* Define the number of identification
variables. If you want all of the cities to be contained in one layer, don't define any. */
%let NIDVARS=0;
/* Define the output parameters for the cities. */
/* The locations will stay the same, so
you only need to redefine CATHOW and SPAHOW to update the catalog entries and append the spatial data sets for the second import. */
%let CATHOW = UPDATE;
%let SPAHOW = APPEND;
/* Initiate the batch import by executing the SCL entry a second time; this time to add the points to the boundaries. */
DM 'AF C=SASHELP.GISIMP.BATCH.SCL';
When the import completes, you can open the map named SASUSER.NC.NC. This map displays the state and county boundaries for North Carolina. You can choose to display the city points on the map.
Examples of Batch Importing 55