HTML Data Set Formatter

Formatting Data Sets Using the HTML Data Set Formatter

The Data Set Formatter enables you to format your SAS data sets as HTML tables so that you can display the information using Web browsers. Using attributes of the Data Set Formatter, you can:

The formatter also supports advanced formatting controls, such as:

To better understand what the Data Set Formatter can do for you, take a look at the Data Set Formatter usage examples.

BY-Group Processing with the Data Set Formatter

SAS software enables you to process observations in a data set that are ordered or grouped according to the values of one or more variables. This method is referred to as BY-group processing. The HTML Data Set Formatter supports BY-group processing in both batch and interactive mode.

When you use BY-group processing with the Data Set Formatter, the formatter creates a separate table for each BY group. The data set does not have to be sorted. If the data set is not sorted or indexed, the entries in each BY-group table appear in the order in which they are encountered in the data set. If you want the data sorted in an order not provided by an index, you should run the SORT procedure on the data set first then run the Data Set Formatter.

Note: BY-group processing with the Data Set Formatter does not support BY variables named NOT or SAME.

Using Style Sheets with the Data Set Formatter

You can use style sheets with all of the Formatting Tools. Due to the fact that each formatter operates on a specific kind of SAS output or data, some arguments behave differently for each formatter. This section describes style sheet information that is specific to the Data Set Formatter. Basic information about style sheet support is provided in Using Style Sheets, which you should read before continuing with the information here.

To use style sheets, your macro invocation must contain:

All three formatters have arguments that enable you to put style information on elements of your output. Using these arguments with the formatters is described in the general style sheet documentation that is referenced above. The remainder of this section discusses style sheet formatting options that are unique to the Data Set Formatter.

Formatting rows based on the variable

You can instruct the Data Set Formatter to place CLASS=value on the TR tag. But more importantly, you can base the formatting instruction on the data associated with a particular variable in the data set.

Example 1:
You have a data set that contains sales closed this quarter and one of the variables is area. Your company has sales regions divided into six areas. Because you know all the possible values for area, you could, without modifying your data set, format the resulting table so that each row of data is color-coded by area.

To accomplish the task described in example 1:

  1. Create a style sheet that has a CLASS element named for each possible value for area. The following is a sample style sheet that you might create.

      h1.yelbg {background: yellow}
        .north {background: blue} 
        .south {background: #ffffe2}
        .east {background: #c0c0c0}
        .west {background: green}
        .canada {background: white}
        .mexico {background: white, font-weight: bold}
    Figure 1: Sample style sheet
  2. Make sure that you are including the area variable in your output. You can use the VAR argument to specify which variables to include in the output.

  3. Add rowssvar=area, to your Data Set Formatter invocation. ROWSSVAR is the argument that adds CLASS=value to each row that contains a value for area in the table.

  4. Specify the proper syntax to embed or link to your style sheet. See the style sheet syntax.

  5. Run the Data Set Formatter and view the results in a browser that supports style sheets.

In example 1, the variable has a limited number of values, which allows you to add each value to your style sheet. Suppose the variable contains a large value set or is a calculated value that cannot be predicted in advance. You can create or use any valid SAS format to generate a smaller or more predictable set of values. Then, use the ROWSSFMT argument to instruct the Data Set Formatter to use CLASS=format value on each row that contains the variable.

Example 2:
Assume you are using the same data set described in example 1. Only this time, you want to color-code the rows in the table based on the sales value not the region. Since the value of the sale could be any number, you don't want to create a style for every possible number. You can create a SAS format and use your existing style sheet.

For this example, you can either add new CLASS elements to your existing style sheet, or write your SAS format to use the names of CLASS elements that already exist in your style sheet. As you increase your use of style sheets, you will often choose between these two options. However, for the ease of discussion, this example defines additional CLASS elements to the style sheet shown in Figure 1.

To accomplish the task described in example 2:

  1. Create a SAS format.

    For this example, create a format named range. The format contains a set of ranges. When the format is applied, the variable value is evaluated and a format value is associated with it based on the range in which it falls. You could use the following as your format:

       proc format;
          value range low-25000="low"
                      25000-50000="mid"
                      50000-100000="high"
                      100000-high="over";
       run;
  2. Add CLASS elements that match your format values to your style sheet. For this example, add these classes to the style sheet used in example 1:

      h1.yelbg {background: yellow}
        .north {background: blue} 
        .south {background: #ffffe2}
        .east {background: #c0c0c0}
        .west {background: green}
        .canada {background: white}
        .mexico {background: white, font-weight: bold}
        .low {background: white} 
        .mid {background: #ffffe2}
        .high {background: #c0c0c0}
        .over {background: yellow}
        #redfg {color: red} 
    Figure 2: Updated sample style sheet
  3. Make sure that you are including the sales variable in your output. You can use the VAR argument to specify which variables to include in the output.

  4. Add rowssvar=sales, to your Date Set Formatter invocation. ROWSSVAR is the argument that adds CLASS=value to each row that contains a value for sales.

  5. Add rowssfmt=range., to your invocation. ROWSSFMT is the argument that adds CLASS=format value to each row that contains a value for the specified variable. You must use both ROWSSVAR and ROWSSFMT.

  6. Specify the proper syntax to embed or link to your style sheet. See the style sheet syntax.

  7. Run the Data Set Formatter and view the results in a browser that supports style sheets.

Formatting table cells based on the variable

In the previous examples, you learned how to apply formatting instructions to an entire row of a table based on variable values. This section explains how to apply formatting instructions to a cell in the table. You can instruct the Data Set Formatter to place CLASS=value or ID=value on the TD tag. Like with ROWSSVAR and ROWSSFMT, you can base the formatting instruction on the data associated with a particular variable in the data set.

Example 3:
You have a data set that contains employment information such as employee name, gender, hire date, office location, etc. You want format this information into a nice HTML table. To make it easy for each branch manager to locate the employees that work in their office, you decide to highlight the table cell that includes the branch office name.

Your company has a style sheet that contains colors that have been approved for use on your intranet. Because you are required to use this style sheet, you must create a format that works with the CLASS values in the style sheet. The following is part of the corporate style sheet, which is named approved.css:

  .blue {background: #0000FF}
  .teal {background: #008F93} 
  .green {background: #008740}
  .yellow {background: #FFFF00}
  .beige {background: #FFFFE2}
  .gray {background: #c0c0c0}
  .white {background: white, font-weight: bold} 
  #warning {color: red}
Figure 3: Sample style sheet

To accomplish the task described in example 3:

  1. Create a SAS format.

    For this example, create a format named color. The format associates the name of a CLASS in your style sheet with each branch office name.

  2. Make sure that you are including the branch variable in your output, and that you are including CLASSFMT with the VAR argument.

    The VAR line might look like the following:

        var=branch(classfmt=color) name hire sex phone mail,

    CLASSFMT adds CLASS=format value to each table cell that contains a branch office name. See Applying styles to variables for a description of how to use this syntax.

  3. Link to your style sheet by adding the following to your Data Set invocation:

        sshref1=approved.css,
        sstype1=text/css,
        ssrel1=stylesheet,
        ssmedia1=screen,
  4. Run the Data Set Formatter and view the results in a browser that supports style sheets.

_____________________

For more information, see: