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

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
1 ACCEPTED SOLUTION

Accepted Solutions
Darrell_sas
SAS Employee

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

7 REPLIES 7
ballardw
Super User

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.

jordanruegg
Fluorite | Level 6

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.

ballardw
Super User

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?

Darrell_sas
SAS Employee

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

 

jordanruegg
Fluorite | Level 6

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?

 

ballardw
Super User

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

jordanruegg
Fluorite | Level 6

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.

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
  • 7 replies
  • 2924 views
  • 1 like
  • 3 in conversation