BookmarkSubscribeRSS Feed
Pyrite | Level 9

How can I tell sas to move labels which have little spaces on map, outside the map and instead use arrows to point to the province?

Super User

This sounds like an annotate data set is required.

Your requirement will be to determine the x,y coordinates of where everything needs to appear on the map.

Then build a data set.


The SAS supplied macro %annomac should be available if you have GMAP installed. Add this code:


to make all of the other annotate macros available. The log will show how to get descriptions of what the various macros will help you do such as

%helpano( help);

My first step would be to use the %Maplabel macro to create a data set with the text of the labels and an approximately centered location.

If the text only needs to me moved a bit you can adjust the x and or y coordinates manually in a data step with code like

Data want_anno;

   set maplabelset;

   select (mapidvariable);

       when(someidvalue) do; x=0.5; y=0.06; end;

       when(otheridvalue) x=0.04; /* example of only one coordinate needing adjustment*/




If you actually cannot get a location that will display the text then you need to specify:

   1) a location for the actual text label

   2) the text to display at that location   (these two can be done with a %label macro call.)

   3) specify a start location (near the text label) coordinates,

   4) end location for an arrow (the %maplabel location likely

   5) specify the arrow appearance options  (the %arrow macro should work for 3,4,5)


The individual annotate macros such as %arrow should appear in the online documentation as well.


Insert the appropriate macro calls for the id variable in the SELECT block for the ids that need the moved label and the arrow.


Then tell gmap to use the annotate data set. Please be aware the you can use two annotate data sets, one on the Proc Statement and one on a plot statement like CHORO.


If you are likely to have many of these maps it will likely be a good idea to create a permanent data set with the appropriate coordinates to reuse.

Pyrite | Level 9

Hi ballardw, thanks for your reply and explanation. I will try that and leave a feedback. Thanks

Pyrite | Level 9

Hi bellardw,

I wasn't successful with the code. Maybe you could use this datasets on this link to explain it better. Here is the link



Meteorite | Level 14

One of my recent blog posts had a map with custom label placement, and arrows pointing from the label to the geographic area. I used lat/long coordinates for both the geographic label, and the area on the map:


Here's a link to the code I used:



Pyrite | Level 9

Hi Robert, thanks I will try that to see if I will be successful

Pyrite | Level 9

Hey Robert,

I have being struggling with your code samples but am not getting through.

This is my code,  maybe am doing something wrong but I can't fish it out. Please I need your help again. The labels are for the map on the link

Here is the code I have written so far

data anno_drawarrow;
length function $8 color $8;
set annolabel;
flag= 0;
xsys='2'; ysys='2'; hsys='3'; when='a';
function='label'; color='black'; size=2.5;
if id not in (ab, md, un, cd)  then 
		text=incidence; position='5'; 
else if id in (ab, md, un, cd)then 
	text=incidence; position='6'; output;
    function='move'; text=''; position=''; 

if  flag=1 then 
        position=''; text=''; 
		function='draw'; size=.25; 

here ist the maplabel data.

I want some labels to go outside the map and use arrows to label them

Meteorite | Level 14

Do you have the lat/long coordinates for where you want the labels to be placed, and where you want the arrows to point to?

Pyrite | Level 9

Hello Robert,

thanks for your reply.  Its about the same datasets you helped me to solve on this link:

Yes I have the latitudes and longitudes in the test.sas7bdat

I tried to follow your example but I could unfortunately solve the problem. I will be glad if you can help me here.


I have attached the datasets again but they are the same as that on this link:


Pyrite | Level 9

I'm still counting on any help

Meteorite | Level 14

My latest example also shows a couple of variations on the technique of labeling areas on a map:






SAS is headed back to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team.

Interested in speaking? Content from our attendees is one of the reasons that makes SAS Innovate such a special event!

Submit your idea!

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.

Get the $99 certification deal.jpg



Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 10 replies
  • 3 in conversation