Sorting Columns

Topics:

How to:

Reference:

You can sort report information horizontally using the ACROSS phrase. This creates columns in your report. The total number of ACROSS columns is equal to the total number of ACROSS sort field values multiplied by the total number of display fields.

A request can include up to 128 sort phrases consisting of any combination of BY and ACROSS phrases.

The maximum number of display fields your report can contain is determined by a combination of factors. In general, if a horizontal (ACROSS) sort field contains many data values, you may exceed the allowed width for reports, or create a report that is difficult to read. For details, see Displaying Report Data.

You can produce column totals or summaries for ACROSS sort field values using ACROSS-TOTAL, SUBTOTAL, SUB-TOTAL, RECOMPUTE, and SUMMARIZE. For details, see Including Totals and Subtotals.

Syntax: How to Sort Columns

ACROSS sortfield

where:

sortfield

Is the name of the sort field.

Reference: Usage Notes for Sorting Columns

  • You cannot use text fields as sort fields. Text fields are those described in the Master File with a FORMAT value of TX.
  • You can use a temporary field created by a DEFINE command, or by the DEFINE attribute in a Master File, as a sort field. However, you cannot use a temporary field created by a COMPUTE command as a sort field. You can accomplish this using the BY TOTAL phrase or indirectly by first creating a HOLD file that includes the field, and then reporting from the HOLD file. HOLD files are described in Saving and Reusing Your Report Output.
  • For an ACROSS phrase, the SET SPACES parameter controls the distance between ACROSS sets. For more information, see .
  • If you specify several sort fields when reporting from a multipath data source, all the sort fields must be in the same path.
  • In styled output formats (PDF, HTML, DHTML, PPT, PPTX, and XLSX), the width of ACROSS titles and ACROSS values above the data columns is defined as the largest width of all data columns, and associated column titles, within the ACROSS groups. To change the size of the ACROSS groups, apply SQUEEZE, WRAP, or WIDTH definitions to the data columns within each group.
  • Each sort field value is displayed only once in the report unless you change this default using the SET BYDISPLAY command. For example, if there are six employees in the MIS department, a report that declares
    PRINT LAST_NAME ACROSS DEPARTMENT

    prints MIS once, followed by six employee names.

Example: Sorting Columns With ACROSS

The following illustrates how to show the total salary outlay for each department. This request is sorted horizontally with an ACROSS phrase.

TABLE FILE EMPLOYEE
SUM CURR_SAL ACROSS DEPARTMENT
END

The output is:

DEPARTMENT
MIS                    PRODUCTION
---------------------------------
$108,002.00           $114,282.00

Notice that the horizontal sort displays a column for each sort field (department).

Controlling Display of an ACROSS Title for a Single Field

How to:

Using the SET ACRSVRBTITL command, you can control the display of an ACROSS column title in an ACROSS group. The behavior of the title is determined by the number of verb columns in the ACROSS group. The field count is affected by the following features, which add internal matrix columns to the report:

  • Fields in a heading or footing.
  • Fields whose display is suppressed with the NOPRINT phrase.
  • Reformatted fields (which are normally counted twice).
  • A COMPUTE command referencing multiple fields.

Syntax: How to Control Display of an ACROSS Title for a Single Field

SET ACRSVRBTITL = {HIDEONE|ON|OFF}
ON TABLE SET ACRSVRBTITL {HIDEONE|ON|OFF}

where:

HIDEONE

Suppresses the title when there is only one display field, or there is only one display field and the request contains one or more of the features that add internal matrix columns to the report. This value is the default.

ON

Always displays the title even if there is only one display field.

OFF

Suppresses the title when there is only one display field. Displays the title when there is only one display field and the request contains one or more of the features that add internal matrix columns to the report. This is legacy behavior.

Example: Hiding an ACROSS Title With ACRSVRBTITL

The following request against the GGSALES data source has a display field in the heading:

SET ACRSVRBTITL=HIDEONE
TABLE FILE GGSALES
HEADING
"Sales Report for <CATEGORY with ACRSVRBTITL=HIDEONE"
" "
SUM DOLLARS AS Sales
BY CATEGORY
ACROSS REGION
WHERE CATEGORY EQ 'Food'
ON TABLE SET PAGE NOPAGE
ON TABLE SET ACROSSTITLE SIDE
ON TABLE SET ACROSSLINE SKIP
ON TABLE SET STYLE *
TYPE=REPORT, GRID=OFF, FONT='ARIAL', SIZE=9, SQUEEZE=ON,$
TYPE=TITLE,JUSTIFY=LEFT,BACKCOLOR=RGB(102 102 102),COLOR=RGB(255 255 255),STYLE=BOLD,$
TYPE=HEADING, SIZE=11, STYLE=BOLD,JUSTIFY=CENTER, $
TYPE=ACROSSTITLE,STYLE=BOLD,$
TYPE=ACROSSVALUE,BACKCOLOR=RGB(218 225 232),$
END

Using the default value for ACRSVRBTITL, HIDEONE, suppresses the ACROSS title Sales, even though the heading displays a field value that adds a report column to the internal matrix.

The report output is shown in the following image:

If you change the SUM command to the following:

SUM DOLLARS/D12CM

the field in the heading and the reformatted dollar sales values add report columns to the internal matrix, but the ACROSS title Sales is still suppressed.

The report output is shown in the following image:

Using the ACRSVRBTITL value ON, without reformatting the dollar sales column, does not suppress the ACROSS title Sales because the heading displays a field value that adds a report column to the internal matrix.

The report output is shown in the following image:

If you change the SUM command to the following:

SUM DOLLARS/D12CMC

the field in the heading and the reformatted dollar sales values add report columns to the internal matrix, so the ACROSS title Sales is not suppressed.

The report output is shown in the following image:

With the setting ACRSVRBTITL=OFF, the field in the heading adds a report column to the internal matrix, and the ACROSS title Sales is not suppressed.

The report output is shown in the following image:

If you change the SUM command to the following:

SUM DOLLARS/D12CM

the field in the heading and the reformatted dollar sales values add report columns to the internal matrix, and the ACROSS title Sales is not suppressed.

The report output is shown in the following image:

Positioning ACROSS Titles on Report Output

How to:

Reference:

In a report that uses the ACROSS sort phrase to sort values horizontally across the page, by default, two lines are generated on the report output for the ACROSS columns. The first line displays the name of the sort field (ACROSS title), and the second line displays the values for that sort field (ACROSS value). The ACROSS field name is left justified above the first ACROSS value.

If you want to display both the ACROSS title and the ACROSS values on one line in the PDF, HTML, EXL2K report output, you can issue the SET ACROSSTITLE = SIDE command. This command places ACROSS titles to the left of the ACROSS values. By default, the titles are right justified in the space above the BY field titles. You can change the justification of the ACROSS title by adding the JUSTIFY attribute to the StyleSheet declaration for the ACROSSTITLE component. If there are no BY fields, the heading line that is created by default to display the ACROSS title will not be generated.

This feature is designed for use in requests that have both ACROSS fields and BY fields. For requests with ACROSS fields but no BY fields, the set command is ignored, and the ACROSS titles are not moved.

Note that for certain output formats, you can control whether column titles are underlined using the SET TITLELINE command. SET ACROSSLINE is a synonym for SET TITLELINE. For information, see .

Syntax: How to Control the Position of ACROSS Field Names

SET ACROSSTITLE = {ABOVE|SIDE}

where:

ABOVE

Displays ACROSS titles above their ACROSS values. ABOVE is the default value.

SIDE

Displays ACROSS titles to the left of their ACROSS values, above the BY columns.

Reference: Usage Notes for SET ACROSSTITLE

  • When the ACROSS value wraps, the ACROSS title aligns with the top line of the wrapped ACROSS values.
  • The ACROSS title spans the width of the BY columns. If the ACROSS title value is larger than the width of the BY columns on the current page, the value is truncated. The first panel may have more BY fields than subsequent panels, if SET BYPANEL is set to a value smaller than the total number of BY fields.
  • This setting will not create a new column within the report for the title placement.
    • If the request does not have any BY fields, the ACROSS title is not moved.
    • With BYPANEL=OFF, the ACROSS title is not displayed on subsequent panels.
  • WRAP is not supported for ACROSSTITLE with SET ACROSSTITLE=SIDE.

Example: Placing the ACROSS Title on the Same Line as the ACROSS Values

The following example against the GGSALES data source has two ACROSS sort fields, CATEGORY and PRODUCT. SET ACROSSTITLE=SIDE moves the ACROSS title to the left of the ACROSS values. With BYPANEL=ON the ACROSS titles are repeated in the same location on each subsequent panel.

SET ACROSSTITLE=SIDE
SET BYPANEL=ON
TABLE FILE GGSALES
SUM 
     DOLLARS/I8M AS ''
BY REGION
BY ST
BY CITY
ACROSS CATEGORY
ACROSS PRODUCT
WHERE PRODUCT NE 'Capuccino';
ON TABLE SET PAGE-NUM ON 
ON TABLE NOTOTAL
ON TABLE PCHOLD FORMAT PDF
ON TABLE SET HTMLCSS ON
ON TABLE SET STYLE *
     UNITS=IN,
     SQUEEZE=ON,
     ORIENTATION=PORTRAIT,
$
TYPE=REPORT,
     FONT='ARIAL',
     SIZE=10,
     BORDER=LIGHT,
$
TYPE=ACROSSVALUE,
     WRAP=ON,
$
ENDSTYLE
END

The ACROSS title Category displays to the left of the ACROSS values Coffee, Food, and Gifts. The ACROSS title Product displays to the left of the ACROSS values Espresso, Latte, Biscotti, and so on. The ACROSS titles are right-justified above the space occupied by the BY field names Region, State, and City. Notice that the ACROSS value Croissant wraps onto a second line, and the ACROSS title is aligned with the top line. The following shows panel 1:

The following shows panel 2:

Example: ACROSS Title Spacing

The following example against the GGSALES data source has two BY fields and two ACROSS fields. This example does not set borders on and does not enable wrapping of the ACROSS values. SET ACROSSTITLE=SIDE moves the ACROSS title to the left of the ACROSS values. The SET BYPANEL=1 command repeats only the first BY field on the second panel. To prevent the ACROSS titles from being truncated to fit above the BY field on the second panel, the first BY field has an AS name that is longer than the default name:

SET ACROSSTITLE=SIDE
SET BYPANEL=1
TABLE FILE GGSALES
SUM 
     DOLLARS/I8M AS ''
BY ST AS 'State Code'
BY CITY
ACROSS CATEGORY AS 'Categories'
ACROSS PRODUCT AS 'Products'
WHERE PRODUCT NE 'Capuccino';
ON TABLE SET PAGE-NUM ON 
ON TABLE NOTOTAL
ON TABLE PCHOLD FORMAT PDF
ON TABLE SET HTMLCSS ON
ON TABLE SET STYLE *
     UNITS=IN,
     SQUEEZE=ON,
     ORIENTATION=PORTRAIT,
$
TYPE=REPORT,
     FONT='ARIAL',
     SIZE=10,
   $
ENDSTYLE
END

The first panel follows:

Because of the SET BYPANEL=1 command, the space available above the BY fields on the second panel is smaller than the space on the initial panel. The AS name State Code adds space for the ACROSS titles, so the titles are not truncated on the second panel:

Example: Specifying Background Color for ACROSS Values With ACROSSTITLE=SIDE

The following request against the GGSALES data source places the ACROSS titles next to the ACROSS values and sets matching styling of font color and backcolor for the ACROSSTITLES, ACROSSVALUES, and column titles to white text on grey background color.

SET ACROSSTITLE=SIDE
TABLE FILE GGSALES
SUM DOLLARS/I8M AS ''
BY REGION
BY ST
BY CITY
ACROSS CATEGORY
ACROSS PRODUCT
WHERE CATEGORY EQ 'Coffee' OR 'Food';
ON TABLE SET PAGE-NUM NOPAGE
ON TABLE NOTOTAL
ON TABLE PCHOLD FORMAT HTML
ON TABLE SET HTMLCSS ON
ON TABLE SET STYLE *
SQUEEZE=ON,UNITS=IN,ORIENTATION=PORTRAIT,$
TYPE=REPORT,FONT='ARIAL',SIZE=10,BORDER=LIGHT,$
TYPE=ACROSSTITLE,COLOR=WHITE, BACKCOLOR=GREY,$
TYPE=ACROSSVALUE,COLOR=WHITE, BACKCOLOR=GREY,$ 
TYPE=TITLE,COLOR=WHITE, BACKCOLOR=GREY,$
ENDSTYLE
END

The output has a grey background color and white text for the ACROSS titles, ACROSS values, and column titles.

Using Multiple Horizontal (ACROSS) Sort Fields

You can sort a report using more than one sort field. When several sort fields are used, the ACROSS phrase order determines the sorting order. The first ACROSS phrase sets the first sort break, the second ACROSS phrase sets the second sort break, and so on. Each successive sort is nested within the previous one.

Example: Sorting With Multiple Horizontal (ACROSS) Phrases

The following request sorts the sum of current salaries, first by department and then by job code.

TABLE FILE EMPLOYEE
SUM CURR_SAL
ACROSS DEPARTMENT ACROSS CURR_JOBCODE
WHERE CURR_SAL GT 21500
END

The output is:

DEPARTMENT                                                          
                  MIS                               PRODUCTION                   
CURR_JOBCODE
                  A17              B04              A15              A17  
------------------------------------------------------------------------
           $27,062.00       $21,780.00       $26,862.00       $29,700.00

Collapsing PRINT With ACROSS

How to:

Reference:

The PRINT command generates a report that has a single line for each record retrieved from the data source after screening out those that fail IF or WHERE tests. When PRINT is used in conjunction with an ACROSS phrase, many of the generated columns may be empty. Those columns display the missing data symbol.

To avoid printing such a sparse report, you can use the SET ACROSSPRT command to compress the lines in the report. The number of lines is reduced within each sort group by swapping non-missing values from lower lines with missing values from higher lines, and then eliminating any lines whose columns all have missing values.

Because data may be moved to different report lines, row-based calculations such as ROW-TOTAL and ACROSS-TOTAL in a compressed report are different from those in a non-compressed report. Column calculations are not affected by compressing the report lines.

Syntax: How to Compress Report Lines

SET ACROSSPRT = {NORMAL|COMPRESS}
ON TABLE SET ACROSSPRT{NORMAL|COMPRESS}

where:

NORMAL

Does not compress report lines. NORMAL is the default value.

COMPRESS

Compresses report lines by promoting data values up to replace missing values within a sort group.

Reference: Usage Notes for SET ACROSSPRT

  • Compression applies only to ACROSS fields, including ACROSS … COLUMNS. It has no effect on BY fields.
  • The only data values that are subject to compression are true missing values. If the value of the stored data is either 0 or blank and the metadata indicates that MISSING is ON, that value is not subject to compression.

Example: Compressing Report Output With SET ACROSSPRT

The following request against the GGSALES data source prints unit sales by product across region:

TABLE FILE GGSALES                           
PRINT UNITS/I5                                     
BY PRODUCT                                   
ACROSS REGION                              
WHERE DATE FROM '19971201' TO '19971231';    
WHERE PRODUCT EQ 'Capuccino' OR 'Espresso';  
ON TABLE SET ACROSSPRT NORMAL 
ON TABLE SET PAGE NOPAGE
END

Each line of the report represents one sale in one region, so at most one column in each row has a non-missing value when ACROSSPRT is set to NORMAL.

                  Region                                         
                  Midwest     Northeast   Southeast   West       
Product           Unit Sales  Unit Sales  Unit Sales  Unit Sales 
-----------------------------------------------------------------
Capuccino                  .         936           .           . 
                           .         116           .           . 
                           .         136           .           . 
                           .           .        1616           . 
                           .           .        1118           . 
                           .           .         774           . 
                           .           .           .        1696 
                           .           .           .        1519 
                           .           .           .         836 
Espresso                1333           .           .           . 
                         280           .           .           . 
                         139           .           .           . 
                           .        1363           .           . 
                           .         634           .           . 
                           .         406           .           . 
                           .           .        1028           . 
                           .           .        1014           . 
                           .           .         885           .
                           .           .           .        1782
                           .           .           .        1399
                           .           .           .         551

Setting ACROSSPRT to COMPRESS promotes non-missing values up to replace missing values within the same BY group and then eliminates lines consisting of all missing values.

TABLE FILE GGSALES                           
PRINT UNITS/I5                                     
BY PRODUCT                                   
ACROSS REGION                              
WHERE DATE FROM '19971201' TO '19971231';    
WHERE PRODUCT EQ 'Capuccino' OR 'Espresso';  
ON TABLE SET ACROSSPRT COMPRESS  
ON TABLE SET PAGE NOPAGE 
END

The output is:

                  Region                                        
                  Midwest     Northeast   Southeast   West      
Product           Unit Sales  Unit Sales  Unit Sales  Unit Sales
----------------------------------------------------------------
Capuccino                  .         936        1616        1696
                           .         116        1118        1519
                           .         136         774         836
Espresso                1333        1363        1028        1782
                         280         634        1014        1399
                         139         406         885         551

WebFOCUS

Feedback