Data visualization with SAS programming

How to use gproject or annotation correctly?

Reply
Frequent Contributor
Posts: 77

How to use gproject or annotation correctly?

Below is my code. I don't know where it goes wrong. Two address points don't show up in the graph. Maybe I don't do gproject or annotation correctly. Any help is appreciated.

===============================================
data city1;
city='Milford'; state_cd='DE'; zip=19963; state=10;
output;
city='Hartly'; state_cd='DE'; zip=19953; state=10;
output;
run;

proc geocode zip
addressstatevar=state_cd
data=city1
out=city2;
run;

proc gproject deg
data=city2
out=city3;
id state;
run;

data city_anno;
set city3;
when='A';
xsys='3'; ysys='3';
function='label';
color='cx330099'; size=1.25; text='J';
position='5'; style='special';
run;

data de1;
set maps.states;
if state=10;
run;

title;

proc gproject
data=maps.states
out=de;
id state;
where state=10;
run;

pattern v=e;

proc gmap map = de
anno = city_anno;
id state;
choro state / nolegend;
run;
quit;
SAS Employee
Posts: 977

Re: How to use gproject or annotation correctly?

There were several problems, such as...

You can't gproject the map & annotate data sets separately, or they'll both be projected into different/independent x/y min/max.

Need to convert the lat/long degrees to radians, so they are in the same coordinate system as the map.

Need to multiply the long by -1, so it is the same (eastlong/westlong) as the map's longitude.

Need to use the data coordinate system xsys/ysys=2, rather than 3.

I think the following modified code will do what you're wanting:



data city1;
city='Milford'; state_cd='DE'; zip=19963; state=10;
output;
city='Hartly'; state_cd='DE'; zip=19953; state=10;
output;
run;

proc geocode zip
addressstatevar=state_cd
data=city1
out=city2;
run;

data city_anno; set city2;
/* Convert degrees to radians */
x=atan(1)/45 * x * -1;
y=atan(1)/45 * y;

when='A'; xsys='2'; ysys='2'; hsys='3';
function='pie'; color='cx330099'; size=1.5;
style='psolid'; rotate=360;
annoflag=1;
run;

data de;
set maps.states (where=(state=10));
run;

/* combine the map & annotate, gproject them together, then separate them */
data combined; set de city_anno;
proc gproject data=combined out=combined;
id state;
run;
data de city_anno; set combined;
if annoflag=1 then output city_anno;
else output de;
run;

title;
goptions cback=white;
pattern v=s c=white;
proc gmap map=de anno=city_anno;
id state;
choro state / levels=1 nolegend coutline=gray55;
run;
quit;
Frequent Contributor
Posts: 77

Re: How to use gproject or annotation correctly?

This is really helpful! Thanks, Robert.
Frequent Contributor
Posts: 77

Re: How to use gproject or annotation correctly?

If I change the size to be 0.5 in data city_anno step, proc gmap doesn't produce a round dot for me.

data city_anno; set city2;
/* Convert degrees to radians */
x=atan(1)/45 * x * -1;
y=atan(1)/45 * y;

when='A'; xsys='2'; ysys='2'; hsys='3';
function='pie'; color='cx330099'; size=0.5;
style='psolid'; rotate=360;
annoflag=1;
run;
SAS Employee
Posts: 977

Re: How to use gproject or annotation correctly?

Ahh! ... round dots! This topic has gone round & round on the forum lately!
(pun intended! Smiley Wink

Depending on what kind of output you can use, you might try some other goptions device= settings, such as pdf or svg. Depending on several factors, you might get dots with smoother more-round edges.

Also, you might try an style='pempty' (outline) rather than style='psolid' - sometimes that makes a difference.

There are also several other tips in a recent thread - I'll let you check them out there, rather than repeat them here.

Also, in the 9.3 version (currently under development), there have been some improvements ... but it will be a while before 9.3 is completed, and available to customers.

This might be a good issue to call-in to Tech Support, so they can document in the official system that this is causing problems. This will help make it more likely to get fixed.
Ask a Question
Discussion stats
  • 4 replies
  • 292 views
  • 0 likes
  • 2 in conversation