10.3 - Column Headings and Justification

10.3 - Column Headings and Justification

The DEFINE statement is not only useful for associating variables with formats, specifying column widths, and setting column spacings. The DEFINE statement can also be used to set the justification, and specify the headings, of your columns.

To define a column heading, you merely need to enclose the desired text of your heading in quotation marks in the DEFINE statement.

Example 10.9

The following program uses the DEFINE statement to set the headings for the Yards and Type variables, respectively, as Total Yardage and Type of Course:

PROC REPORT data = stat480.penngolf NOWINDOWS HEADLINE;
     title 'Some Pennsylvania Golf Courses';
     column Name Year Type Par Yards;
	 define Yards / format = comma5.0 'Total Yardage' 
                    width = 7 spacing = 4;
	 define Type / 'Type of Course' spacing = 6;
RUN;
Some Pennsylvania Golf Courses
Name Year Type of Course Par Total Yardage
Toftrees 1968 Resort 72 7,018
Penn State Blue 1921 Public 72 6,525
Centre Hills 1921 Private 71 6,392
Lewistown CC . Private 72 6,779
State College Elks 1973 SemiPri 71 6,369
Park Hills CC 1966 SemiPri 70 6,004
Sinking Valley CC 1967 SemiPri 72 6,755
Williamsport CC 1909 Private 71 6,489
Standing Stone CC 1973 SemiPri 70 6,593
Bucknell GC 1960 SemiPri 70 6,253
Mount Airy Lodge 1972 Resort 72 7,123

In many cases, you'll need to set the width of the columns so that they accommodate the headings, as is done here for the Yards variable. Launch and run the SAS program, and review the output to convince yourself that, in the resulting report, the headings of the Yards and Type variables are indeed as defined.

If you don't like the way SAS splits long headings across multiple rows, you can take control of it yourself by using a split character in the column label. When the REPORT procedure encounters the split character in a column heading, it breaks the heading and continues the heading on the next line. The split character itself does not appear in the heading. To use a split character, you can do either of the following:

  • Use the default forward slash (/) as the split character.
  • Define a split character by using the SPLIT= option in the PROC REPORT statement, and then use the split character in the column labels.

Let's take a look at another example.

Example 10.10

The following program uses the default forward slash as a split character for the defined column labels of the Yards and Type variables:

PROC REPORT data = stat480.penngolf NOWINDOWS HEADLINE;
     title 'Some Pennsylvania Golf Courses';
     column Name Year Type Par Yards;
	 define Yards / format = comma5.0 'Total/Yardage' 
                    width = 7 spacing = 4;
	 define Type / 'Type of/Course' spacing = 6 width = 8;
RUN;
Some Pennsylvania Golf Courses
Name Year Type of Course Par Total Yardage
Toftrees 1968 Resort 72 7,018
Penn State Blue 1921 Public 72 6,525
Centre Hills 1921 Private 71 6,392
Lewistown CC . Private 72 6,779
State College Elks 1973 SemiPri 71 6,369
Park Hills CC 1966 SemiPri 70 6,004
Sinking Valley CC 1967 SemiPri 72 6,755
Williamsport CC 1909 Private 71 6,489
Standing Stone CC 1973 SemiPri 70 6,593
Bucknell GC 1960 SemiPri 70 6,253
Mount Airy Lodge 1972 Resort 72 7,123

You might want to note that we modified the width of the Type column so that it can now accommodate the length of the column label as it is now defined to be split. Launch and run the SAS program, and review the output to convince yourself that the column labels are split as requested. How does it look? Hmmm, perhaps it might look a bit better now if we centered the Yards and Type columns. Let's go ahead and do that.

Ooops, just one more thing before we do ... you might want to first try out the other method of using a split character. To change the split character to an asterisk (*), say, let's have you attach the SPLIT = option:

split = '*'

just after HEADLINE and before the semicolon in the PROC REPORT statement in Example 10.10. Then, modify the labels so that they use the asterisk:

'Total*Yardage'

and:

'Type of*Course'

And, re-run the SAS program, and review the output to convince yourself that the modified code worked.

Okay, now back to centering columns. Recall that, by default, the REPORT procedure left-justifies character variables and right-justifies numeric variables in listing output. For each variable that you define, you can instead specify the justification option CENTER, LEFT, or RIGHT in the DEFINE statement.

Example 10.11

The following program uses the DEFINE statement's CENTER option to center the Yards and Type columns in the requested report:

PROC REPORT data = stat480.penngolf NOWINDOWS HEADLINE;
     title 'Some Pennsylvania Golf Courses';
     column Name Year Type Par Yards;
	 define Yards / format = comma5.0 'Total/Yardage' 
                    width = 7 spacing = 4 center;
	 define Type / 'Type of/Course' spacing = 6 
                    width = 8 center;
RUN;
Some Pennsylvania Golf Courses
Name Year Type of Course Par Total Yardage
Toftrees 1968 Resort 72 7,018
Penn State Blue 1921 Public 72 6,525
Centre Hills 1921 Private 71 6,392
Lewistown CC . Private 72 6,779
State College Elks 1973 SemiPri 71 6,369
Park Hills CC 1966 SemiPri 70 6,004
Sinking Valley CC 1967 SemiPri 72 6,755
Williamsport CC 1909 Private 71 6,489
Standing Stone CC 1973 SemiPri 70 6,593
Bucknell GC 1960 SemiPri 70 6,253
Mount Airy Lodge 1972 Resort 72 7,123

Launch and run the SAS program, and review the output to convince yourself that the CENTER option centers the formatted values within the specified column width, as well as the headings that appear over the values. That is in fact how each option works. The RIGHT option right-justifies the formatted values within the specified column width, as well as the headings that appear over the values, and the LEFT option left-justifies the formatted values within the specified column width, as well as the headings that appear over the values.


Legend
[1]Link
Has Tooltip/Popover
 Toggleable Visibility