SAS How To's

How to Easily Create a Beautiful Title in SAS

Titles are indispensable for good and understandable plots and reports. However, understanding how to create a title in SAS might cause you headaches. Therefore, in this article, we discuss how to add a title in SAS and use some options to enhance its appearance.

Basically, you create a title in SAS with the TITLE statement. The statement starts with the title keyword followed by the text of the title between (double) quotes. You can add additional arguments to the statement to change the aspect of the title, e.g. the font, the font size, and the color.

How to Add a Title in SAS

If you run a SAS procedure that creates a report or a plot, SAS doesn’t add a title. At most, it shows the name of the procedure.

You can create a title by adding the TITLE statement to your SAS code. More precisely, by placing the statement just before you call the procedure.

The TITLE statement consists of the title keyword, followed by the text of the title between (double) quotes. You close the statement with a semi-colon. Neither a RUN nor QUIT statement is necessary to execute the statement.

In the example below, we show how to create a title and print the first 10 rows of the IRIS table from the SASHELP library with PROC PRINT.

title "Iris Flower Data Set";
proc print data=sashelp.iris (obs=10) noobs;
run;
Add a Title to a plot in SAS

You can create titles for other procedures as well, such as PROC MEANS.

title "Descriptive Statistics of Iris Flower Data Set";
proc means data=sashelp.iris;
run;
Create a title in SAS

Also, SAS allows you also to add a title to a graph or plot (e.g., a scatter plot). If you use the SGPLOT procedure to create your plot and combine it with the TITLE statement, SAS will place the title within the borders of the plot.

title "Scatter Plot of Iris Flower Data Set";
proc sgplot data=sashelp.iris;
    scatter x = petallength  y = sepallength;
run;
Add a title to a plot in SAS

How to Create a Titles and Subtitles in SAS

Sometimes you might want to break a title into multiple lines. Unfortunately, if you use multiple TITLE statements consecutively, SAS will only show the last title. For example:

title "The First Line of the Title";
title "The Second Line of the Title";
title "The Third Line of the Title";
proc print data=sashelp.iris (obs=10) noobs;
run;

If you want to create a title covering multiple lines by using different TITLE statements, then the last TITLE statement overwrites the preceding statements.

However, you can create a title in SAS of multiple lines by adding the n-argument to the statement. This argument specifies the relative line that contains the title line. In other words, SAS prints the text of title1 before the text of title2, the text of title2 before title3, and so on.

You can create a title of up to 10 lines.

In the example below, we create a title that consists of 3 lines.

title1 "Iris Flower Data Set";
title2 "Ronald Fisher - 1936";
title3 "SASHELP.IRIS";
proc print data=sashelp.iris (obs=10) noobs;
run;
Create Titles and Subtitles in SAS

How to Change the Font Size of a Title

A common question regarding titles in SAS is how to change the font size.

You can easily change the font size of a title in SAS by adding the height=-option to the TITLE statement. You only need to specify the desired dimension and the units of measure (e.g., centimeters (cm), inches (in), or printer’s points (pt)).

Note that, the height=-option only affects the text that follows after the option. So, if you put the option at the end of the statement, the font size won’t change.

The SAS code below illustrates how to use the height=-option to change the font size of a title.

title1 height=20pt "Iris Flower Data Set";
title2 height=15pt "Iris Flower Data Set";
title3 height=10pt "Iris Flower Data Set";
proc print data=sashelp.iris (obs=10) noobs;
run;
Change the Font Size of a Title in SAS

How to Change the Font of a Title

Similar to the font size, you can also change the font of a title (e.g., Times New Roman, Helvetica, or Comic Sans).

To change the font of a SAS title, you use the font=-option. The option starts with the font keyword, followed by an equal sign and the name of the desired font between (double) quotes. You can use all the fonts that are installed on your system.

Remember, you must place the font=-option before the text of the title to be effective.

The SAS code below shows how to create 3 titles with different fonts.

title1 font="Times New Roman" "Iris Flower Data Set";
title2 font="Arial" "Iris Flower Data Set";
title3 font="Comic Sans MS" "Iris Flower Data Set";
proc print data=sashelp.iris (obs=10) noobs;
run;
Change the Font of a Title in SAS

How to Change the Allignment of a Title

By default, SAS centers the title above the plot or report. However, under some circumstances, you might want to change the default location.

You can change the alignment of a SAS title with the justify=-option. This option starts with the justify keyword, followed by an equal sign and the desired location. You can align the title in the center, to the left, or to the right. Like all other title options, you must place the justify=-option at the beginning of the TITLE statement.

Instead of writing left, right, or center to specify the location of the title, you can also use their alias, namely L, R, or C.

The example below illustrates how to change the position of a title in SAS.

title1 justify=left "Iris Flower Data Set";
title2 justify=right "Ronald Fisher - 1936";
title3 justify=center "SASHELP.IRIS";
proc print data=sashelp.iris (obs=10) noobs;
run;
Change the Allignment of a Title in SAS

How to Change the Color of a Title

Another option that the TITLE statement offers to enhance its appearance is to change the color.

You can change the color of a title in SAS with the color=-option. The option starts with the color keyword, then an equal sign, and finally the name of the desired color between (double) quotes. You must place this option before the text to have any effect.

You can change the color of a title into many other colors. So, if you are interested in all possible colors, this page might be useful.

The SAS code below creates three titles with different colors (red, blue, and green).

title1 color="red" "Iris Flower Data Set";
title2 color="blue" "Iris Flower Data Set";
title3 color="green" "Iris Flower Data Set";
proc print data=sashelp.iris (obs=10) noobs;
run;
Change the color of a title in SAS

How to Emphasize a Title (Bold, Italic, Underline)

Another way to emphasize (parts of) a title is by making the text bold, italic, or underlined.

You can make the text of a SAS title bold and/or italic by placing the bold and/or italic keyword at the beginning of the TITLE statement. Likewise, to underline the title, you use the underline=1 option.

The example below demonstrates how to make a title Italic, Bold, or Underlined.

title1 italic "Iris Flower Data Set";
title2 bold "Iris Flower Data Set";
title3 underlin=1 "Iris Flower Data Set";
proc print data=sashelp.iris (obs=10) noobs;
run;
Emphasize a Title in SAS with Bold, Italic, and Underline

How to Combine Multiple Title Options in SAS

Above we have discussed how to create a title and how to change its appearance with one option.

However, you can also combine multiple options to change the look of a title. Remember that a title option only affects the text that it is preceding. Hence, if you combine multiple options and place them at different locations in the TITLE statement, you can create very special titles.

For example:

title1 italic font="Times New Roman" height=25pt "Iris Flower Data Set";
title2 "Iris" bold color="red" " Flower" color="blue" height=6pt " Data Set";
title3 underlin=1 "Iris Flower" underlin=0 italic font="Comic Sans MS" " Data Set";
proc print data=sashelp.iris (obs=10) noobs;
run;
Combine SAS Title Options

How to Remove a Title in SAS

Once you have defined a title, SAS shows this title before the output of all procedures by default.

For example, in the SAS code below we have one TITLE statement and two procedures. If you execute the code at once, SAS shows the title before both the output of the PRINT procedure and the MEANS procedure.

title "Iris Flower Data Set";
proc print data=sashelp.iris (obs=10) noobs;
run;
 
proc means data=sashelp.iris;
run;

So, is there a way to remove titles in SAS?

In SAS, you can remove old titles with an empty TITLE statement. That is to say, just the title keyword and a semi-colon. By doing so, SAS won’t show titles anymore.

For example:

title "Iris Flower Data Set";
proc print data=sashelp.iris (obs=10) noobs;
run;
title;
 
proc means data=sashelp.iris;
run;

3 thoughts on “How to Easily Create a Beautiful Title in SAS

Comments are closed.