BookmarkSubscribeRSS Feed
Xinxin
Obsidian | Level 7

Hello,

My data is like this:

ZIPcode Cases   longi   lati
43613   1   -83.604452  41.704307
44140   1   -81.92148   41.48982
46052   1   -86.470531  40.051603
48009   22  -83.213883  42.544619
48017   6   -83.151815  42.535396
48021   7   -82.946167  42.463894
48025   19  -83.265758  42.523195

I want to map the cases by zip code. The outline should be of the zip code boundary and the shading should be according to number of cases, darker as cases increase.

 

If anyone can tell me how to do this either in SAS or R, that'll be great. I'm very new to R...Tried a lot of code I found online but can't get what I want. Any help is appreciated.

 

Thank you!

 

 

10 REPLIES 10
ChrisNZ
Tourmaline | Level 20

There are many resources that show you how. Have you seen Creating ZIP Code-Level Maps with SAS

Xinxin
Obsidian | Level 7

I have looked at code online but I don't know how to project my data on the map and get the shading. Also, I don't want the whole country or state but zoomed in to a part of the state. Also, yesterday and today, the govt census site is down, so will check again later. Thanks.

GraphGuy
Meteorite | Level 14

To plot your data on a choropleth map (filling in the boundaries of the zip codes with shades/colors), you won't need your lat/long coordinates, and you won't necessarily need to project the map (for a small-ish area, such as when dealing with zip codes, it won't really matter whether the map is projected or unprojected, or what projection it's using). But we don't ship zipcode boundary maps, so you'll have to download them from somewhere, and Proc Mapimport them, etc. (as the papers/examples show).

 

I know this isn't exactly what you're asking for, but ... something that might be a lot less work, and might be a good way to get started, would be to plot your data with a Proc SGmap bubble map. Here's a quick example, using the data you posted:

 

data my_data;
input ZIPcode Cases longi lati;
datalines;
43613 1 -83.604452 41.704307
44140 1 -81.92148 41.48982
46052 1 -86.470531 40.051603
48009 22 -83.213883 42.544619
48017 6 -83.151815 42.535396
48021 7 -82.946167 42.463894
48025 19 -83.265758 42.523195
;
run;

 

proc sgmap plotdata=my_data noautolegend;
openstreetmap;
bubble x=longi y=lati size=cases / fillattrs=(color=red);
run;

 

SGMap3.png

 

 

brookeewhite1
Quartz | Level 8

I tried using your sample code but received this error several times in my log: "ERROR 180-322: Statement is not valid or it is used out of proper order."  Any idea what the problem might be? 

 

I'm using SAS Enterprise Guide 7.1 and For Base SAS Software 9.4_M4.

ballardw
Super User

First you would be better off starting your own thread and reference this one as part of what you attempted.

 

Any time you get an error you should copy from the log the entire procedure or data step code along with all of the notes, warnings or messages. That way we have some chance of knowing what the problem is. Without it my answer is typically "42" as there is no context.

Copy the text from the log, on the forum open a text box using the </> icon above the message window and paste the text.

The text box is important because the message window will reformat pasted text which means the the diagnostic messages that SAS often supplies with errors like this appear in the wrong place.

 

I will bet that your log shows some word or characters with underscores. That is what SAS found as incorrect.

Common causes of this particular error are

1) not ending a previous statement with a semicolon

2) incorrectly placing a semicolon so that code that should be part of something, such as a function call or calculation, appears as the start of a statement and not continuation as expected.

3) use of a statement that is not defined in the current procedure or legal in a data step.

GraphGuy
Meteorite | Level 14

When running 'new' procs such as Proc SGmap, you'll need to have the newest version of SAS possible. You indicate you have version 9.4_m4 ... that version is pretty old. If you're wanting to use SGmap, I would recommend getting 9.4m7 which was released in the fall of 2020 (that's when a lot of the SGmap features were released https://blogs.sas.com/content/graphicallyspeaking/2020/09/25/new-sgmap-features-in-sas-9-4m7/ )

brookeewhite1
Quartz | Level 8

Thank you.  I had a feeling my version might be the issue. I don't have the authority to perform the software upgrade at work, unfortunately.  Any suggestions for a workaround using the old version?

ballardw
Super User

@brookeewhite1 wrote:

Thank you.  I had a feeling my version might be the issue. I don't have the authority to perform the software upgrade at work, unfortunately.  Any suggestions for a workaround using the old version?


First, since any paid license should come with the ability to maintain current version, talk to whoever is responsible for maintaining software and arrange to update the software per your license.

 

Do you have a license to SAS/Graph? The alternatives would likely involve Proc Gmap which comes with that part of the license.

 

Second, you may need to provide more information about your specific graphing need. Which means you should start your own thread on the forum instead of adding on to something else. Such as provide example data of your data, as the author of this post did, and what you require for output.

brookeewhite1
Quartz | Level 8

Yes I have access to SAS Graph.  I'm not trying to work with my own data yet, I was starting at the very beginning with using the sample data and code provided here, figuring the first step would be to get that to work.  I probably just need a generic example of Proc GMAP to start with then.

 

Thanks!

ballardw
Super User

Please start your own thread. Please. You are moving further and further away from the original topic of this thread and further responses do not belong in this one.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 10 replies
  • 3696 views
  • 5 likes
  • 5 in conversation