BookmarkSubscribeRSS Feed
Anita_n
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?

10 REPLIES 10
ballardw
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:

%annomac;

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*/

       otherwise;

   end;

 

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.

Anita_n
Pyrite | Level 9

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

Anita_n
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 https://communities.sas.com/t5/SAS-GRAPH-and-ODS-Graphics/using-colors-on-maps-gmap/m-p/457338#M1572...

 

thanks

GraphGuy
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:

 

https://blogs.sas.com/content/sastraining/2018/04/23/can-you-guess-which-10-rivers-produce-95-of-oce...

 

Here's a link to the code I used:

 

http://robslink.com/SAS/democd97/rivers_and_plastic_info.htm

 

rivers_and_plastic_map.png

Anita_n
Pyrite | Level 9

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

Anita_n
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 https://communities.sas.com/t5/SAS-GRAPH-and-ODS-Graphics/using-colors-on-maps-gmap/m-p/457338#M1572...

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 
	do;
		text=incidence; position='5'; 
		output;
	end;
else if id in (ab, md, un, cd)then 
	do;
	text=incidence; position='6'; output;
    function='move'; text=''; position=''; 
	flag=1;output;
end;

if  flag=1 then 
	do;	
        position=''; text=''; 
		function='draw'; size=.25; 
		flag=0;output;
	end;
run;

here ist the maplabel data.

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

GraphGuy
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?

Anita_n
Pyrite | Level 9

Hello Robert,

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

https://communities.sas.com/t5/SAS-GRAPH-and-ODS-Graphics/using-colors-on-maps-gmap/m-p/457338#M1572...

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:

https://communities.sas.com/t5/SAS-GRAPH-and-ODS-Graphics/using-colors-on-maps-gmap/m-p/457338#M1572...

 

Anita_n
Pyrite | Level 9

I'm still counting on any help

GraphGuy
Meteorite | Level 14

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

 

http://robslink.com/SAS/democd98/guatemala_volcanoes_info.htm

http://robslink.com/SAS/democd98/guatemala_volcanoes.htm

 

guatemala_volcanoes.png

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

Discussion stats
  • 10 replies
  • 1497 views
  • 0 likes
  • 3 in conversation