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

I have a statewide set of data that I use to produce maps.  I need to label the towns on a map of each county.  The maps come out fine but the labels from towns surrounding each county show up outside of the county area.


Here is how I create the dataset for the labels:

%annomac;

%maplabel (UseMe, UseMe, Labels2use, name, sd_b county,

          font=Arial Black, color=black, size=.8, hsys=3);

run;


'sd_b' is the identifying field for each town and 'county' is the name of the county it is in.  I added county to the list of variables hoping that it would supress the lables not in the county being created but it didn't help.


To create the county maps I use this:

proc gmap

map=work.UseMe

data=work.UseMe

annotate=Labels2use;

by county;

id sd_b;

choro count/

uniform;

run;

quit;

How do I get the procedure to only print the names of the towns that are in the county that is currently being produced instead of all the names that fit in the plot area?

1 ACCEPTED SOLUTION

Accepted Solutions
Ray
Calcite | Level 5 Ray
Calcite | Level 5

I figured it out!  I had the Annotate statement in the wrong place.

These statements work and only display the names of the towns for the county being produced.


%annomac;
%maplabel (useme, useme, Labels2use, name, sd_b county,
          font=Arial Black, color=black, size=.8, hsys=3);
run;

*MAKE COUNTY MAP;
data useme; set useme;
proc sort; by county;
run;

data labels2use; set labels2use;
proc sort; by county;
run;


proc gmap
map=work.UseMe
data=work.useme;
by county;
id sd_b;
choro count/
annotate=labels2use
uniform;
run;
quit;

View solution in original post

4 REPLIES 4
art297
Opal | Level 21

I would think that adding country as a segment variable would have the exact opposite effect of what you are trying to do.  Did you run it with only supplying sd_b as the id variable in the macro?

http://support.sas.com/documentation/cdl/en/graphref/63022/HTML/default/viewer.htm#a002362924.htm

Ray
Calcite | Level 5 Ray
Calcite | Level 5

I tried running the maplabel macro with and without county and it makes no difference.

I found this in the online help which leads me to believe I need to move the annotate option but I'm not sure where to put it.

Using the BY Statement with the Annotate Facility

If a procedure that is using BY-group processing also specifies annotation with the ANNOTATE= option in the PROC statement, the same annotation is applied to every graph generated by the procedure.

If you specify annotation with the ANNOTATE= option in the action statements for a procedure, the BY-group processing is applied to the Annotate data set. In this way, you can customize the annotation for the output from each BY group by including the BY variable in the Annotate data set and by using each BY-variable value as a condition for the annotation to be applied to the output for that value.

Ray
Calcite | Level 5 Ray
Calcite | Level 5

I figured it out!  I had the Annotate statement in the wrong place.

These statements work and only display the names of the towns for the county being produced.


%annomac;
%maplabel (useme, useme, Labels2use, name, sd_b county,
          font=Arial Black, color=black, size=.8, hsys=3);
run;

*MAKE COUNTY MAP;
data useme; set useme;
proc sort; by county;
run;

data labels2use; set labels2use;
proc sort; by county;
run;


proc gmap
map=work.UseMe
data=work.useme;
by county;
id sd_b;
choro count/
annotate=labels2use
uniform;
run;
quit;

GraphGuy
Meteorite | Level 14

Good job on your self-help, Ray! 🙂

Note that this is a very powerful feature of annotate -- it allows you to specify annotations in a way that the 'by' group subsetting will be applied (such as what you were wanting), or annotations that will appear in all the by group graphs ... or both!

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
  • 4 replies
  • 1173 views
  • 0 likes
  • 3 in conversation