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;
By merging the response data with the map data, you're making life more difficult than it has to be!
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...
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.
By merging the response data with the map data, you're making life more difficult than it has to be!
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...
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Lock in the best rate now before the price increases on April 1.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.