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

Hello,

 

I would like to create a world map showing various locations and a custom legend witch consecutive numbers representing the locations.

The first problem is that the caption is too "high", this is, number 3 should be on the coast, not in the Atlantic.

Second, I would like to get a legend, which shows which location is represented by which number, this is, 1 .. New York, 2.. Ann Arbor, etc.

 

* Sites;
Data Position;
  Input @1 City $ @30 y @42 x;
  x=atan(1)/45 * x;
  y=atan(1)/45 * y;
  Nr=_N_;
  Datalines;
New York                     40.714352   74.0059731
Ann Arbor                    42.2808256  83.7430378
Santiago de Compostela       42.8782132  8.5448445
Dalian                       38.914003   -121.614682
;
Run;

* World Map;
Data World (Rename=(long=x lat=y));
   Set maps.world (Drop=x y);
Run;

* Sites+Map;
Data Combo;
  Set Position World;
Run;

Proc GProject Data=Combo Out=Proj Project=Gall;
  ID Cont ID;
Run; Quit;

Data Map Anno;
  Set Proj;
  If City='' Then Output Map;
  Else Output Anno;
Run; Quit;

Data Anno;
  Length Color $8. Text $20. Style $25.;
  Set Anno;
  Retain xsys ysys '2' function 'label' when 'a';
  text=Compress(Put(Nr,Best2.));
  color='steel';
  position='2';
  size=0.8;
  Output;
run;

Pattern1 v=ms r=77 c=PALG;
Title1 'Title';
Proc GMap Data=Map Map=Map;
  ID Cont ID;
  Choro ID / Anno=Anno COutLine=white;
Run; Quit;

 

Thanks&kind regards

1 ACCEPTED SOLUTION

Accepted Solutions
GraphGuy
Meteorite | Level 14

Since there is no automatic legend for the things you annotate, you'll have to create your own custom legend.

You could do that by also annotating a legend, or perhaps putting the desired legend text in a 'footnote'...

 

Title1 'Title';
footnote "1-someplace  2-other  3-another";
Proc GMap Data=Map Map=Map;
  ID Cont ID;
  Choro ID / nolegend Anno=Anno COutLine=white;
Run;

 

 

View solution in original post

3 REPLIES 3
Darrell_sas
SAS Employee

For #1, use POSITION='5'; instead of '2'.  5 places the text at the center of the center.

GraphGuy
Meteorite | Level 14

Since there is no automatic legend for the things you annotate, you'll have to create your own custom legend.

You could do that by also annotating a legend, or perhaps putting the desired legend text in a 'footnote'...

 

Title1 'Title';
footnote "1-someplace  2-other  3-another";
Proc GMap Data=Map Map=Map;
  ID Cont ID;
  Choro ID / nolegend Anno=Anno COutLine=white;
Run;

 

 

MikeZdeb
Rhodochrosite | Level 12

Hi.  There is a way to add a legend that contains just the text you would like to display (map with legend attached) ...

 

NOTE: revised version eliminates data step that separates the projected data set into the MAP and ANNOTATE data sets and uses WHERE statements in subsequent steps to use the correct portion of the projected data set

 

Data Position;
Input @1 City $20. @30 y @42 x;
x=atan(1)/45 * x;
y=atan(1)/45 * y;
Nr=_N_;
Datalines;
New York                     40.714352   74.0059731
Ann Arbor                    42.2808256  83.7430378
Santiago de Compostela       42.8782132  8.5448445
Dalian                       38.914003   -121.614682
;

 

* create a macro variable with text to be used in a LEGEND statement;

proc sql noprint;
select catt('j=l "',nr,': ',city,'"') into :cities separated by ' ' from position;
quit;

 

* combine positions and world map (no Antarctica);
Data combo;
Set position maps.world (Drop=x y Rename=(long=x lat=y) where=(cont ne 97));
run;

 

Proc GProject Data=Combo Out=Proj Project=Gall;
ID Cont ID;
Run; 

 

Data Anno;
Retain xsys ysys '2' hsys '3' function 'label' style 'calibri' size 2.5 color 'steel' when 'a';
Set proj;
where ^missing(city);
text=cat(nr);
run;

goptions reset=all ftext='calibri' htext=2.5 gunit=pct;

* use the macro variable in the LEGEND statement;
legend1 origin=(3,20)pct mode=share
value=none shape=bar(.00001,.00001)pct label=(&cities);

Pattern1 v=ms r=77 c=PALG;

Title1 'MAP WITH MODIFIED LEGEND' ls=2;

Proc GMap Data=proj Map=proj;
where missing(city);
ID Cont ID;
Choro ID / Anno=Anno COutLine=white legend=legend1 statistic=first;
Run;
Quit;


worldmap.png

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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