Data visualization with SAS programming

How do I stop my labels from being cut off on SAS Maps?

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 6
Accepted Solution

How do I stop my labels from being cut off on SAS Maps?

Hello All,

 

I have been working on a Map that has multiple values as labels over each US State. I found a macro that would allow me to do this and place the labels for the small New England states over the Atlantic. My issue is that when I generate the map the labels are cutoff by the edge of the map. Is there a way to increase the whitespace around the map?

 

This is the macro that I've been using:

 

%macro mapanno(dsn, mapvar, mapvar2, mapvar3, textsize) ;
  data mapanno ;
    length function $8 text $20 size 8 ;
    retain xsys ysys '2' hsys '3' when 'a' style "'Arial'" ;

    merge &dsn.( keep = state &mapvar. &mapvar2. &mapvar3. in = xm ) maps.uscenter ;
      by state ;
    where fipstate( state ) not in('PR' ) ;
    lagocean = lag( ocean ) ;
    size = &textsize. ;

    if ocean = 'Y' then do ;
      if not missing( &mapvar. ) then text = catx( " / ", &mapvar2.
        , ifc( vtype( &mapvar ) = 'C', &mapvar.
          , strip( putn( &mapvar3., vformat( &mapvar3. ) ) ) ) , ifc( vtype( &mapvar ) = 'C', &mapvar3.
          , strip( putn( &mapvar3., vformat( &mapvar3. ) ) ) )) ;
      else text = fipstate( state ) ;
      function = 'label' ;
      position = '3' ;
      output ;
      function = 'move' ;
      output ;
    end ;

    position = '5' ;
    if ocean = 'N' then do ;
      if lagocean = 'Y' then do ;
        function = 'draw' ;
        size = &textsize / 15 ;
      end ;
      else do ;
        function = 'label' ;
        if not missing( &mapvar ) then do ;
          position = '2' ;
          text = ifc( vtype( &mapvar2. ) = 'C', &mapvar2.
            , strip( putn( &mapvar2., vformat( &mapvar2. ) ) ) ) ;
          output ;
		   position = '8' ;
          text = ifc( vtype( &mapvar3. ) = 'C', &mapvar3.
            , strip( putn( &mapvar3., vformat( &mapvar3. ) ) ) ) ;
          output ;
          position = '5' ;
          text = ifc( vtype( &mapvar. ) = 'C', &mapvar.
            , strip( putn( &mapvar., vformat( &mapvar. ) ) ) ) ;
        end ;
        else text = fipstate( state ) ;
      end ;
      output ;
    end ;
  run ;
%mend ;

The attached image is the output when I call the macro. Normally (With shorter data lengths) there are labels connected to the end of the lines on the east coast.

 

Please let me know if there is some graphics setting that I could change to get the map to show all of my labels.

 

Thanks!


USMAP.PNG

Accepted Solutions
Solution
‎01-18-2017 09:25 AM
SAS Employee
Posts: 170

Re: How do I stop my labels from being cut off on SAS Maps?

You might look at the data set "mapanno" and make sure you have text data for the annotate variable in thoses 'ocean' states.

 

View solution in original post


All Replies
Super User
Posts: 11,134

Re: How do I stop my labels from being cut off on SAS Maps?

Does your log show any notes about attempting to place values outside of the map area?

Also note that your Ocean='Y' may be creating a TEXT result that does not fit within the declared 20 characters.

 

Print or view the value for text in your mapanno dataset where Ocean=Y.

 

 

Where I have had to use a similar display I have ended up having to supply start coordinates for each line of label text to go where I want and without overwriting each other based on the target area which might be possible with your Maryland and Washington D.C. values.

Occasional Contributor
Posts: 6

Re: How do I stop my labels from being cut off on SAS Maps?

Thanks for the quick reponse.

 

My log does not show any notes about attempting to place values outside of the map area.

 

I changed the format length to 40 characters and that does catch some truncation issues in the non-border states (a problem I was about to start working on). But it doesn't fit the coastal labels on the map still.

Super User
Posts: 11,134

Re: How do I stop my labels from being cut off on SAS Maps?

You might show some of hte data for your ocean='Y' states. I can't tell if you have the position for the label text to be starting at the end of the line segment or not, or actually even how the line(arrow or what ever) is being created in your annotate data set. I would expect something to adjust the x,y coordinates for the label text but I'm not quite seeing it. Could that be hidden in the macor variables?

Solution
‎01-18-2017 09:25 AM
SAS Employee
Posts: 170

Re: How do I stop my labels from being cut off on SAS Maps?

You might look at the data set "mapanno" and make sure you have text data for the annotate variable in thoses 'ocean' states.

 

Occasional Contributor
Posts: 6

Re: How do I stop my labels from being cut off on SAS Maps?

The text is actually not writing to the data set in this instance.

 

I keep getting the following warning:

 

WARNING: In a call to the CATX function, the buffer allocated for the result was not long enough to contain the concatenation of

all the arguments. The correct result would contain 56 characters, but the actual result might either be truncated to 40

character(s) or be completely blank, depending on the calling environment. The following note indicates the left-most

argument that caused truncation.

NOTE: Argument 4 to function CATX(' / ','RE / 0 / $0.'[12 of 200 characters shown],'UCC / 0 / $0'[12 of 200 characters

shown],'Titled / 0 /'[12 of 200 characters shown]) at line 64 column 143 is invalid.

 

The label that I am trying to put into each of these areas is a concatenation of three sting variables I'm importing from Excel. So there is a catx statement happening in a data step before this macro is run, then there is a catx occuring to bring in the three variables output. It does make a very long variable. Is there anyway to allow catx to hold the entire length of this?

 

Super User
Posts: 11,134

Re: How do I stop my labels from being cut off on SAS Maps?

SET the length of the text variable to 56 with a length statement.

Occasional Contributor
Posts: 6

Re: How do I stop my labels from being cut off on SAS Maps?

I figured that problem out now - it was actually an issue with my catx statement in the data step that preps the data before the macro is run. I think I'm pretty close to figuring this out, I'm just going to have to figure out how to get some of the labels to go to the northwest of their state as opposed to the southeast. I think that will make the text readable.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 7 replies
  • 319 views
  • 1 like
  • 3 in conversation