BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Harvey_D
Calcite | Level 5

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;


screenshot.png
1 ACCEPTED SOLUTION

Accepted Solutions
GraphGuy
Meteorite | Level 14

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

2 REPLIES 2
ballardw
Super User

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.

GraphGuy
Meteorite | Level 14

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 1622 views
  • 3 likes
  • 3 in conversation