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?
That was simple. Thanks! Can I get an explanation of why this works, but my code didn't?
Makes sense! Thanks!
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.
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?
Correct, because the content of that title statement is still global.
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
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!
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.
Ready to level-up your skills? Choose your own adventure.