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?
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.
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?
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
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 open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.