ODS

SAS ODS PDF: How to create a full-width separator line under titles

Simon 23 vues
Niveau de difficulté
Débutant
Publié le :

When generating SAS© reports in PDF format, it is common to want to refine the header's formatting. A frequent aesthetic request is to insert a horizontal line separating the title area from the report body.

However, there is often confusion between underlining text and creating a container border. If you have ever tried using the underline option in the TITLE statement, you have probably noticed that it only underlines the text (the characters). If your title is short, the line stops abruptly.

The question is therefore: how to get a separator line that extends across the entire width of the page, regardless of orientation (Portrait or Landscape) and text length?

The common mistake: the wrong style element

To change the overall appearance of reports, using PROC TEMPLATE is the recommended method. However, choosing the right style element to modify is crucial.

Many users try to modify the SysTitleandFooterContainer element by applying border rules to it (frame=below, rules=rows). Although this seems logical, this approach often fails to produce the expected visible borders in the PDF destination.

The solution: Target TitlesAndFooters

To get a border that acts as a separator line under the entire title area, you need to modify the TitlesAndFooters style element.

Here's how to do it by creating a custom style that inherits from an existing one (like styles.statistical or styles.pearl):

SAS ODS PDF: How to create a full-width separator line under titles -
1PROC TEMPLATE;
2 define style styles.MonStylePDF;
3 parent=styles.statistical; /* ou le style de votre choix */
4
5 /* Modification de l'élément conteneur des titres et pieds de page */
6 style TitlesAndFooters from TitlesAndFooters /
7 borderbottomcolor = black
8 borderbottomwidth = 1pt
9 borderbottomstyle = solid;
10 END;
11RUN;

Implementation

Once the template is compiled, you just need to call it when opening your ODS PDF destination:

1ods pdf file="C:\temp\mon_rapport.pdf" style=styles.MonStylePDF;
2 
3title1 "Rapport Mensuel";
4title2 "Données confidentielles";
5 
6PROC PRINT DATA=sashelp.class;
7RUN;
8 
9ods pdf close;

Unlike the underline option, which is a font attribute, the properties defined in TitlesAndFooters apply to the container (the box) that hosts your titles. By defining a bottom border (borderbottom) on this container, SAS© draws a line across the entire width allocated to the page header, creating a clean and professional separation, regardless of the number of characters in your titles.