Formatting very long data point labels in SGPLOT

Accepted Solution Solved
Reply
New Contributor
Posts: 4
Accepted Solution

Formatting very long data point labels in SGPLOT

I am using the following procedure to create data point labels for the top 2 (sorted) cases in my dataset.  

data label_class1;

  keep size_class pha_code PHA_total_unit_cnt total_comp_s8_s9 labelid;

  set resid1s;

  id = _n_;

  if _n_ le 2  then do;

    labelid=cats(pha_code, ":  ", substr(emp_title_text, 1, 20)) ;

  end;

  else if _n_ > 2 then do;

    labelid = .;

  end;

run;quit;

I want the label to include the variables PHA_Code and emp_title_text, separated by a colon.  I've tried using the SUBSTR to limit it to the first 20, but this was only as a last resort and did not work.  This procedure above works fine (with and without the SUBSTR), but when I attempt to run SGPLOT with this labelid I get an empty plot, presumably because the label text is too long to fit on the graph.  If I use only PHA_CODE as the label, everything works fine and that is my label.    How can I format this label so that it can fit?  I am using SGPLOT because of the REFLINE utility, which is something I need.  Thanks in advance!


Accepted Solutions
Solution
‎03-05-2014 02:10 PM
Super User
Posts: 10,460

Re: Formatting very long data point labels in SGPLOT

What do your resolved values of labelid actually look like? Also, how long is LABELID decalred for? I would also try specifying that something like

length labelid $ 40 ; /* just long enough to hold the longest expected value*/

If you suspect a length issue what I would do is try incrementing the length of substr until it fails. If it fails

You may have slightly better results using CATX

labelid= catx(": ",pha_code, substr(emp_title_text,1,2); /* to try adding 2 characters*/

View solution in original post


All Replies
Solution
‎03-05-2014 02:10 PM
Super User
Posts: 10,460

Re: Formatting very long data point labels in SGPLOT

What do your resolved values of labelid actually look like? Also, how long is LABELID decalred for? I would also try specifying that something like

length labelid $ 40 ; /* just long enough to hold the longest expected value*/

If you suspect a length issue what I would do is try incrementing the length of substr until it fails. If it fails

You may have slightly better results using CATX

labelid= catx(": ",pha_code, substr(emp_title_text,1,2); /* to try adding 2 characters*/

New Contributor
Posts: 4

Re: Formatting very long data point labels in SGPLOT

The CATX function worked.  Thank you!  I am now able to get at least 20 characters in there, when I wasn't able to before. 

☑ This topic is SOLVED.

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

Discussion stats
  • 2 replies
  • 159 views
  • 0 likes
  • 2 in conversation