BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Linlin
Lapis Lazuli | Level 10

Dear All,

Attached is a dataset with my friends' state, zip, and gender. I'd like to put the information on a MAP. I have PC 9.3 sas.

Any help is highly appreciated.

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
MikeZdeb
Rhodochrosite | Level 12

hi ... you should be able to use the attached SAS job

it creates three maps:  USA, New England, Massachusetts (this one is linked ... mouse over a STAR brings up info about location and friends)

ps  looks as if the X/Y location of the zip centroid for North Truro (02652) is a little off (in Cape Cod Bay)


usa.pngnewengland.pngmassachusetts.png

View solution in original post

11 REPLIES 11
GraphGuy
Meteorite | Level 14

You could take U.S. zip codes and run them through "proc geocode" and get the latitude/longitude.

You can then annotate markers on a map (using proc gmap and annotate) at those locations.

You could color these markers based on the gender (such as pink for girls, blue for guys).

You could use "ods html" and have mouse-over text to show the names.

The output could be similar to this:

Outdoor Dramas in North Carolina

But you might run into issues such as "what if 2 people are in the exact same zip code?"

It really depends on what you're wanting to use the map for, as to how is the best way to plot the data.

Linlin
Lapis Lazuli | Level 10

Hi Robert,

Thank you for your reply! I am thinking of creating two maps. one using distinct zip code (similar to your output: outdoor dramas in NC), another one using state, and something else to reflect the number of people in the state.

PGStats
Opal | Level 21

Hi Linlin,

One interesting way to present points on a map is to create a KML file for Google Earth. Those files are very small. SAS can be used to create the KML file which will then open directly into Google Earth. Look at http://support.sas.com/resources/papers/proceedings10/052-2010.pdf and the references therein or search "Google Earth" on the SAS support site for information.

Good luck!

PG

PG
Linlin
Lapis Lazuli | Level 10

Thank you PG! I will try that.  - Linlin

PGStats
Opal | Level 21

Hi Linlin,

Here is a prototype of a macro (not well documented, not foolproof) to put your friends locations on Google Earth. Assuming you have GE installed, you can view the result by double-clicking the LinlinFriends.kml file. 

In the macro, I implemented the possibility of changing the shape, color and scale of the symbols, as well as the description that pops up when clicked. You will notice the sophisticated way Google has of dealing with superimposed symbols and the effect of transparency (opacity in Google terms) when symbols are overlaid.

The available shapes are named donut, polygon, open-diamond, square, star, target, triangle, placemark_square, placemark_circle, and shaded_dot.

Have fun!

PG

PG
MikeZdeb
Rhodochrosite | Level 12

hi ... here's another KML idea (produced with attached)

https://maps.google.com/maps?q=http://www.albany.edu/~msz03/lll.kml

Linlin
Lapis Lazuli | Level 10

Hi PG and Mike,

Thank you very much for your help!Smiley Happy I will spend some time to go through all the solutions.

- Linlin

MikeZdeb
Rhodochrosite | Level 12

hi ... you should be able to use the attached SAS job

it creates three maps:  USA, New England, Massachusetts (this one is linked ... mouse over a STAR brings up info about location and friends)

ps  looks as if the X/Y location of the zip centroid for North Truro (02652) is a little off (in Cape Cod Bay)


usa.pngnewengland.pngmassachusetts.png
Linlin
Lapis Lazuli | Level 10

Hi Mike,

Thank you very much! The maps are great. I need time to study your code. Is it possible to use different color for male and female?

Thanks - Linlin

MikeZdeb
Rhodochrosite | Level 12

hi ... I assume you mean the color of the symbols that mark the zip locations

sure, since they are added with annotate you can choose colors

you'd have to make some decisions as to what you do when both males and females are in the same zip (third color?)

attached is a screen capture showing the result of modified SAS code that uses color for gender, symbol size for number of friends (1, 2, 3+) and adds the number of males and females to the title tags ... just substitute the attached SAS code in the section that does the MASS map (the white stars on the lightly shaded background are a bit hard to see, but you can l=play with colors)


mass_friends.png
sophia_SAS
Obsidian | Level 7

Hi Mike-

I found your code to LinLin very helpful for my own analysis.  However, I am having problems with a few parts of the code and am wondering if you can help by explaining your code a bit more - if you have time.

I made the following changes to LinLin's code:

1. Used dots instead of stars as the symbols

2. Kept dot size the same regardless of how many are located at the same zip code.

3. If one zip code has more than one in the same location, then use a "2+" for the text label.  Otherwise, leave the txt blank.

4. Subset this larger map into two maps (i.e. 1 map has only points for gnd1=1 and gnd2=0 and another map is where gnd2=2 and gnd1=0);

Knowing those changes, I have made some modifications to your code to LinLin. (See below.) However, I am still having issues with point 3 and 4.

On point 3, I cannot get the text to say "2+" for those that have 2+ at the same location (and there are a handful.)  Can you please review my code below and see where I am going wrong?  Right now, I am getting a '1' label on every dot.

On point 4, I cannot seem to figure out how to subset the maps using the when statements. I know that I can subset my data in the earlier steps, but was hoping to be more efficient and do it all in one code.

Thank you! If you don't have time, that's just fine! I'm just reaching my end by trying to figure these smaller points out.

data anno;

retain xsys ysys '2' hsys '3' function 'label' style 'wingdings' text '8c'x  size 6 when 'a';

set pfriends;

/*size = ifn(nfriends lt 3, nfriends, 3)*/;

select;

   when (gnd1 and not gnd2) color = 'green';

   when (gnd2 and not gnd1) color = 'blue';

   otherwise                color = 'red';

end;

if nfriends gt 1 then txt = '2+';

else if txt = ' '

gnd1 + 0;

gnd2 + 0;

html = catt('title="' , upcase(city), ' (' , put(zip,z5.) , ')' , '0d'x ,

                        nSDI , txt , '0d'x ,

                        SDI1 , ' SDI' , '0d'x ,

                        SDI0 , ' DR "');

run;

goptions reset=all ftext='calibri' htext=2 gunit=pct xpixels=1024 ypixels=768;

pattern v=e;

* choose legend attributes;

/*legend1 mode=share shape=bar(3,4) label=(position=top 'Labs (Black=SDI, White=DR, Red:Both SDI and DR)')

across=4 origin=(5,20);*/

title1 h=4 "Labs in the Continental US" ls=2;

* whitespace;

title2 a=90  ls=2;

title3 a=-90 ls=2;

footnote1 j=r "SDI=Green, DR=Blue, Both=Red" ls=1;

proc gmap data=anno map=map all annotate=anno;

id state;

choro nfriends / statistic=sum levels=1 nolegend coutline=black ;

run;

quit;

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
  • 11 replies
  • 2202 views
  • 7 likes
  • 5 in conversation