<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Annotate labels for gmap SAS 9.4 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Annotate-labels-for-gmap-SAS-9-4/m-p/628958#M185914</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to figure out the best way to annotate or move my labels so they do not run into each other or county lines.&amp;nbsp; The label variable I am using is xtext which I created in MTMAP. I have tried if and then statements to move x or y but I was unsuccessful.&lt;/P&gt;&lt;P&gt;It would also be nice to get some advice on how to splitting some of the longer labels.&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data MTMap;&lt;BR /&gt;length xtext $20.;&lt;BR /&gt;merge MTcontycnt&amp;nbsp; MTCounties;&lt;BR /&gt;if county=113 then delete;&lt;BR /&gt;by county;&lt;BR /&gt;xtext = cats(name)||' ('||cats(cnt)||')';&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;%annomac;&lt;BR /&gt;%maplabel(MTCounties, MTMap, MTAnnotate, xtext, county, font='Arial', color=black, size=1.3)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;legend1 noframe&lt;BR /&gt;label=(h=2 f=arial '&amp;nbsp; ');&lt;BR /&gt;title h=2 f=arial '&amp;nbsp; ';&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc gmap data=MTMap map=MTMap density=2;&lt;BR /&gt;id county;&lt;BR /&gt;choro cnt / anno=mtannotate legend=legend1 Xsize=8in ysize=5in stretch;&lt;BR /&gt;run;&lt;BR /&gt;quit;&lt;/P&gt;</description>
    <pubDate>Mon, 02 Mar 2020 23:19:55 GMT</pubDate>
    <dc:creator>Whitlea</dc:creator>
    <dc:date>2020-03-02T23:19:55Z</dc:date>
    <item>
      <title>Annotate labels for gmap SAS 9.4</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Annotate-labels-for-gmap-SAS-9-4/m-p/628958#M185914</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to figure out the best way to annotate or move my labels so they do not run into each other or county lines.&amp;nbsp; The label variable I am using is xtext which I created in MTMAP. I have tried if and then statements to move x or y but I was unsuccessful.&lt;/P&gt;&lt;P&gt;It would also be nice to get some advice on how to splitting some of the longer labels.&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data MTMap;&lt;BR /&gt;length xtext $20.;&lt;BR /&gt;merge MTcontycnt&amp;nbsp; MTCounties;&lt;BR /&gt;if county=113 then delete;&lt;BR /&gt;by county;&lt;BR /&gt;xtext = cats(name)||' ('||cats(cnt)||')';&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;%annomac;&lt;BR /&gt;%maplabel(MTCounties, MTMap, MTAnnotate, xtext, county, font='Arial', color=black, size=1.3)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;legend1 noframe&lt;BR /&gt;label=(h=2 f=arial '&amp;nbsp; ');&lt;BR /&gt;title h=2 f=arial '&amp;nbsp; ';&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc gmap data=MTMap map=MTMap density=2;&lt;BR /&gt;id county;&lt;BR /&gt;choro cnt / anno=mtannotate legend=legend1 Xsize=8in ysize=5in stretch;&lt;BR /&gt;run;&lt;BR /&gt;quit;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Mar 2020 23:19:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Annotate-labels-for-gmap-SAS-9-4/m-p/628958#M185914</guid>
      <dc:creator>Whitlea</dc:creator>
      <dc:date>2020-03-02T23:19:55Z</dc:date>
    </item>
    <item>
      <title>Re: Annotate labels for gmap SAS 9.4</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Annotate-labels-for-gmap-SAS-9-4/m-p/628964#M185917</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/133143"&gt;@Whitlea&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to figure out the best way to annotate or move my labels so they do not run into each other or county lines.&amp;nbsp; The label variable I am using is xtext which I created in MTMAP. I have tried if and then statements to move x or y but I was unsuccessful.&lt;/P&gt;
&lt;P&gt;It would also be nice to get some advice on how to splitting some of the longer labels.&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data MTMap;&lt;BR /&gt;length xtext $20.;&lt;BR /&gt;merge MTcontycnt&amp;nbsp; MTCounties;&lt;BR /&gt;if county=113 then delete;&lt;BR /&gt;by county;&lt;BR /&gt;xtext = cats(name)||' ('||cats(cnt)||')';&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;%annomac;&lt;BR /&gt;%maplabel(MTCounties, MTMap, MTAnnotate, xtext, county, font='Arial', color=black, size=1.3)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;legend1 noframe&lt;BR /&gt;label=(h=2 f=arial '&amp;nbsp; ');&lt;BR /&gt;title h=2 f=arial '&amp;nbsp; ';&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;proc gmap data=MTMap map=MTMap density=2;&lt;BR /&gt;id county;&lt;BR /&gt;choro cnt / anno=mtannotate legend=legend1 Xsize=8in ysize=5in stretch;&lt;BR /&gt;run;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;For my work I have spent a certain amount of time with Idaho county data and by trial and error created a data set with "good" x,y coordinates for placing a one or two line label for each county.&lt;/P&gt;
&lt;P&gt;I started with&amp;nbsp;a set created as you have using the&amp;nbsp;%centroid macro. Then adjusted the x and or y coordinate for counties that needed it (most of our 44 counties). Then made sure to have any of the County identifiers I might need, number, fips, name so I could match output data to the data set. And keep this set in a permanent library.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Found that I really only needed 3 significant digits in most of the coordinates. My code, as I said, trial and error, for the set looks like:&lt;/P&gt;
&lt;PRE&gt;data idmap.countylabel;
   set idmap.countylabel;
   select (countynum);
      when ( 1) do; x=-0.027 ;y=-0.035 ; end;                                                            
      when ( 2) do; x=-0.029 ;y=-0.009 ; end;                                                            
      when ( 3) do; x= 0.024 ;y=-0.049 ; end;                                                             
      when ( 4) do; x= 0.037 ;y=-0.055 ; end;                                                             
      when ( 5) do; x=-0.030 ;y= 0.030 ; end;                                                             
      when ( 6) do; x= 0.023 ;y=-0.039 ; end;                                                             
      when ( 7) do; x= 0.000 ;y=-0.035 ; end;                                                             
   /* continue the obvious pattern*/                                                   
      otherwise;
   end;
run;
&lt;/PRE&gt;
&lt;P&gt;I used a county numeric sequence as it was easier to make code look pretty (i.e. maintain if needed).&lt;/P&gt;
&lt;P&gt;I actually have a number of formats to create other values from the countynum numeric value to get the FIPS and name text.&lt;/P&gt;
&lt;P&gt;Some of the coordinates are the centroid results truncated or rounded just to be complete.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am sure there are fancy algorithms out there but once this is done the only thing I worry is about is placing strings much longer than 10 characters on the typical size maps I make. So I use this as the core annotate with the added label variable and settings such as:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data countyanno;
   merge idmap.countylabel work.labeldata;
   by countynum;
   retain xsys ysys '2' when 'a'  cbox 'white';
   %label (x,y,somevalue,black,0,0,.75,albany,5);
run;
&lt;/PRE&gt;
&lt;P&gt;and see if the result has collisions. If they are short, as I said, no problems. If longer then often I can split text into two segments and tweek the position setting to get enough room based on the countynum value. Something like this (example splits string of two words)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;If length(value) &amp;gt; 15 then do;
   labeltext = scan(value,1);
   /* the position of 2 moves text up and stays centered*/
   %label (x,y, labeltext,color, 0,0,size,style, 2);
   output; 
   labeltext = scan(value,2);
      %label (x,y, labeltext,color, 0,0,size,style, 8);
end;
&lt;/PRE&gt;
&lt;P&gt;or possibly B and E depending on text size. Splitting the text should depend on actual knowledge of the strings involved though.&lt;/P&gt;
&lt;P&gt;If the font is small enough you may use 3 strings at 2, + and 8.&lt;/P&gt;
&lt;P&gt;With your example you already had two values, so it would be easy to leave name and Cnt alone and use something like:&lt;/P&gt;
&lt;PRE&gt;do; 
   %label (x,y, name,color, 0,0,size,style, 2); 
   output; 
   %label (x,y, cnt,color, 0,0,size,style, 8); 
end; &lt;/PRE&gt;</description>
      <pubDate>Mon, 02 Mar 2020 23:53:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Annotate-labels-for-gmap-SAS-9-4/m-p/628964#M185917</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-03-02T23:53:56Z</dc:date>
    </item>
  </channel>
</rss>

