Data visualization with SAS programming

PROC GMAP with census zipcode data. Border lines are filling up the map area.

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

PROC GMAP with census zipcode data. Border lines are filling up the map area.

I am trying to proc gmap an a specific state, and map the borders of the zip codes within that state. When I run the proc gmap I get a map that looks like the attachment - the black border lines fill up much of the map making it useless.

I got the zip code coordinates from the census website. The basics of the code is below.

All help is appreciated, thanks.

/* import census zip code data */

proc mapimport datafile="/folder/proj/&dir/&user/Notes/&prj/Data/tl_2013_us_zcta510.shp"

               out=zipdata;

run;

/* import a list of all Florida's zip codes */

      Data FL_Zips;

  infile "/folder/proj/&dir/&user/Notes/&prj/Data/FL_Zips.csv"

           dlm=',' dsd firstobs=3;

      input

           Zipcode   :  $5.;

    format zipcode $5.     ;

     run;

/* filter for only florida zip codes */

proc sql; create table zipdata2 as

select distinct t1.ZCTA5CE10 as Census_Zip,

                      t1.X,

                      t1.Y

from zipdata t1 left join FL_Zips t2 on (t1.ZCTA5CE10=t2.Zipcode)

where t2.zipcode is not missing

order by Census_Zip;quit;

proc gmap data=Zipdata2 map=Zipdata2 all;

id Census_ZIP;

choro census_zip / statistic=First ;

run;

quit;

Attachment

Accepted Solutions
Solution
‎05-01-2014 01:17 PM
SAS Employee
Posts: 963

Re: PROC GMAP with census zipcode data. Border lines are filling up the map area.

By merging the response data with the map data, you're making life more difficult than it has to be! Smiley Happy

If you leave the 'all' option off the proc gmap, then it will only draw the areas of the map= dataset that have a matching ID in the data= dataset. Therefore I think the following code will do what you're wanting:

/* import census zip code map */
proc mapimport
datafile="/folder/proj/&dir/&user/Notes/&prj/Data/tl_2013_us_zcta510.shp"
out=zipdata;
run;

/* import a list of all Florida's zip codes */
Data FL_Zips;
infile "/folder/proj/&dir/&user/Notes/&prj/Data/FL_Zips.csv" dlm=',' dsd firstobs=3;
input Zipcode : $5.;
format zipcode $5.;
run;

/* make sure the id variable is named the same in both datasets */

Data FL_Zips; set Data FL_Zips;
ZCTA5CE10=Zipcode;
run;

pattern1 v=s c=gray;

proc gmap data=FL_Zips map=Zipdata2 /* all */;
id ZCTA5CE10;
choro segment / levels=1 nolegend;
run;

This little gmap paper I'm working on might also have some tips you can use...

http://robslink.com/SAS/book1/Chapter_05_Maps.pdf

View solution in original post


All Replies
Grand Advisor
Posts: 9,748

Re: PROC GMAP with census zipcode data. Border lines are filling up the map area.

Do not use proc sql to manage map boundary sets as it will reorder data. When the coordinates are scrambled, such as by sql, then the points are connected in a non-sequential order and will not generate a boundary.

Solution
‎05-01-2014 01:17 PM
SAS Employee
Posts: 963

Re: PROC GMAP with census zipcode data. Border lines are filling up the map area.

By merging the response data with the map data, you're making life more difficult than it has to be! Smiley Happy

If you leave the 'all' option off the proc gmap, then it will only draw the areas of the map= dataset that have a matching ID in the data= dataset. Therefore I think the following code will do what you're wanting:

/* import census zip code map */
proc mapimport
datafile="/folder/proj/&dir/&user/Notes/&prj/Data/tl_2013_us_zcta510.shp"
out=zipdata;
run;

/* import a list of all Florida's zip codes */
Data FL_Zips;
infile "/folder/proj/&dir/&user/Notes/&prj/Data/FL_Zips.csv" dlm=',' dsd firstobs=3;
input Zipcode : $5.;
format zipcode $5.;
run;

/* make sure the id variable is named the same in both datasets */

Data FL_Zips; set Data FL_Zips;
ZCTA5CE10=Zipcode;
run;

pattern1 v=s c=gray;

proc gmap data=FL_Zips map=Zipdata2 /* all */;
id ZCTA5CE10;
choro segment / levels=1 nolegend;
run;

This little gmap paper I'm working on might also have some tips you can use...

http://robslink.com/SAS/book1/Chapter_05_Maps.pdf

Post a Question
Discussion Stats
  • 2 replies
  • 702 views
  • 3 likes
  • 3 in conversation