BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
PaigeMiller
Diamond | Level 26
proc sort data=sashelp.class out=class;
    by sex;
run;

title 'Histogram for #byval1';
ods graphics/height=3in width=4in;

options orientation=landscape nobyline;
ods pdf file="test.pdf";
ods layout gridded columns=2 column_gutter=18 advance=BYGROUP;
ods region;
proc sgplot data=class;
    by sex;
    histogram height;
run;
ods layout end;
ods pdf close;

 

Output has unwanted title centered above the two plots, which says "Histogram for #byval1", how do I get rid of this unwanted title and leave only the titles above the individual plots?

 

PaigeMiller_0-1667834813065.png

 

--
Paige Miller
1 ACCEPTED SOLUTION

Accepted Solutions
svh
Lapis Lazuli | Level 10 svh
Lapis Lazuli | Level 10
I would suggest putting the TITLE statement in the PROC instead of prior to your ODS PDF statement.

proc sgplot data=class;
title 'Histogram for #byval1';
by sex;
histogram height;
run;

View solution in original post

8 REPLIES 8
svh
Lapis Lazuli | Level 10 svh
Lapis Lazuli | Level 10
I would suggest putting the TITLE statement in the PROC instead of prior to your ODS PDF statement.

proc sgplot data=class;
title 'Histogram for #byval1';
by sex;
histogram height;
run;
PaigeMiller
Diamond | Level 26

That was simple. Thanks! Can I get an explanation of why this works, but my code didn't?

--
Paige Miller
svh
Lapis Lazuli | Level 10 svh
Lapis Lazuli | Level 10
I think it's because you want the title in the REGION defined by the ODS REGION statement right before your SGPLOT statement. In your original example, you title is being forced into the top of the document before you've defined the region. This provides an example:

https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/odsug/p06ji2uhvayhq5n1eik2z2rf2ga8a.htm#p0dq2...

PaigeMiller
Diamond | Level 26

Makes sense! Thanks!

--
Paige Miller
DanH_sas
SAS Super FREQ

Although TITLE statements are global in nature. their placement within the context of an ODS LAYOUT can affect the timing of when the title is generated. In your example, any TITLE statement before the ODS LAYOUT statement will be generated as a page title (the behavior you saw). A TITLE statement between the ODS LAYOUT statement and the first ODS REGION statement will generate a title within the first cell BEFORE the content of the region is processed. A TITLE statement within the ODS REGION block affects the titles for the procedure output, which was your desired result.

PaigeMiller
Diamond | Level 26

Followup question for @DanH_sas and @svh (and anyone else who might have an answer)

 

Above, I created one layout using ODS LAYOUT GRIDDED, but suppose now I want to create a 2nd such layout in the same program, for example instead of using SASHELP.CLASS, now I also want similar histograms in a layout from SASHELP.CARS, in the same program. It seems to me that then I need to include title; before I create the 2nd ODS LAYOUT GRIDDED, otherwise the title from the SASHELP.CLASS histograms carries over to the 2nd grid of histograms.

 

Do you agree? Or is there some other way?

--
Paige Miller
DanH_sas
SAS Super FREQ

Correct, because the content of that title statement is still global.

Rick_SAS
SAS Super FREQ

A few related comments:

1. At some point you might want to panel graphs and tables that are generated by SAS procedures that generate procedure titles. Use the 
ODS NOPROCTITLE;
option to suppress procedure titles, as shown in https://blogs.sas.com/content/graphicallyspeaking/2017/08/14/advanced-ods-controlling-precisely-outp...

2. Your example shows multiple graphs of the same type (a histogram). In this case, it is sometimes helpful to switch to using the SGPANEL procedure and the PANELBY option, especially if you want to control the placement of labels within cells or coordinate the range of axes. See https://blogs.sas.com/content/iml/2021/02/17/data-driven-titles-sgpanel.html and https://blogs.sas.com/content/iml/2011/08/12/side-by-side-bar-plots-in-sas-9-3.html 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 1382 views
  • 5 likes
  • 4 in conversation