BookmarkSubscribeRSS Feed
KevinViel
Pyrite | Level 9

legend.jpg

 

How can I control the width of the legend when I use KEYLEGEND?  It is truncating my title when it appears that it has ample room based on the width of the plot:

 

  keylegend 
          / title      = "Lab Test"
            down       = 1
            linelength = 10%
            ;

I produced the snippet of the figure using SGPLOT setting the HEIGHT and WIDTH options to the ODS GRAPHICS to 4.5in and 9.0in, respectively.

 

Thank you,

 

Kevin

9 REPLIES 9
Rick_SAS
SAS Super FREQ

Can you please provide the SGPLOT statements you are using? This appears to work in the following example:

 

ods graphics/reset;
proc sgplot data=sashelp.cars;
where type in ('SUV' 'Sedan' 'Wagon' 'Truck');
reg x=weight y=mpg_highway / group=type;
keylegend / title      = "Very Long Legend Title"
            down       = 1
            linelength = 10%
            ;
run;
KevinViel
Pyrite | Level 9

Rick,

 

  Thank you for your suggestion.  I have experimented more.  I used a custom style.  I found that changing the following:

 

"GraphLabelFont"      = ( "&font."
                        , 10pt
                        )

to variations such as:

"GraphLabelFont"      = ( "&font."
                        , 10pt
                        , bold
                        )

eliminated the issue:

 

legend2.jpg

The same was true for changing just the font size to 11pt, for instance.  Surprisingly, decrease the font size to 9pt did not eliminate the issue.  Changing the fontface to "Courier New" with 10pt also eliminated the issue.  Using your code, modified to "match" my original code, I was able to replicate the issue.  Omitting the STYLE = forma option to the ODS RTF statement, the issue resolved.  The offending code that produces:

 

cars.jpg

 

is:

 



ods path ( prepend )
         work.templat
         ( write )
         ;

proc template ;
  define style
         styles.forma2 / store  = work.templat
         ;
    parent = styles.pearl ;
    class GraphFonts
        / "GraphLabelFont"      = ( "Times New Roman"
                                  , 10pt
                                  , bold
                                  )
          "GraphValueFont"      = ( "Times New Roman"
                                  , 10pt
                                  )

          ;
  end ;
run ;

ods path ( remove )
         work.templat
         ;

ods path ( prepend )
         work.templat
         ( read )
         ;


ods graphics/reset;

ods graphics on 
           / width    = 9.0in
             height   = 4.5in
             noborder
    ;

ods rtf
    file        = "&outpath.\&outfile.9b.rtf"
    nogtitle
    nogfootnote
    style       = forma2
    ;

ods listing close ;
ods results ;


proc sgplot data = sashelp.cars ;
where type in ('SUV' 'Sedan' 'Wagon' 'Truck');
reg x=weight y=mpg_highway / group=type ;

keylegend / title      = "Lab Title"
            down       = 1
            linelength = 10%
            ;

  format weight       8.0 ;

run;

ods rtf close ;
ods listing ;
ods noresults ;

 

Thank you,

 

Kevin

Rick_SAS
SAS Super FREQ

Thanks for the reproducible example. @DanH_sas might find your example interesting.

KevinViel
Pyrite | Level 9

Rick,

 

  I understand that you were able to reproduce it?  Perhaps this is an issue with the TEMPLATE?  If so, I am looking forward to Dan's reaction, but that would seem to me that I also should open a tech support ticket? (I will have to create an account for my new employer.)

 

Thank you,

 

Kevin

Rick_SAS
SAS Super FREQ

No, I did not try to reproduce it. I don't have much experience with styles.

DanH_sas
SAS Super FREQ

Hey Kevin,

 

Using your test program, I was not able to reproduce the problem using the latest release. What version of SAS are you running, and on what host?

 

Thanks!
Dan

KevinViel
Pyrite | Level 9

Thanks for the reply.  I have a ticket with Lelia McConnell of SAS Tech Support.  I was able to replicate it in RTF, but the PDF was fine.  I generated them in the same program.  She has the full log and the two output. She requested the _AUTOMATIC_ macro variables and I also provided her the SOURCE from Template.

 

Current version: 9.04.01M5P091317

<SNIPPED>

Operating System: WX64_WKS.

 

 

I will update this thread if (when) I get an answer.

 

Kind regards,


Kevin

DanH_sas
SAS Super FREQ

Hey Kevin,

 

In your RTF run, try adding this to your program and see if you get the correct output.

 

ods graphics / imagefmt=png;

 

It could be an EMF output issue. If so, using PNG should fix it. 

 

Thanks!
Dan

akq08540
Calcite | Level 5
Hi Kevin,

I am having exactly the same issue with the Keylengend title. It seems KeyLegend does not like Time New Roman font. We use SAS 9.4 on X64_SR12R2 platform. Did you get any feedback from SAS tech support on this issue?

Thanks.
Zhihai

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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