Stack Columns Task

About the Stack Columns Task

The Stack Columns task creates an output data set by restructuring selected columns in the input data set so that these columns are transposed into observations. You can use the output data set to analyze values across multiple columns of the input data set. If you group the observations, the selected columns are divided into subgroups that are based on the unique combinations of the grouping values. Each subgroup forms a row of the output data set.
This task is useful when you have a data set in which each observation contains the same type of data in multiple columns and you want to analyze the data across several columns. For example, you could transpose columns that contain monthly temperature readings for various locations across a geographic region. The output data set would contain the monthly temperature readings by location in a single column.

Example: Stacking Columns in the CLASSFIT Data Set

  1. In the Tasks section, expand the Data folder and double-click Stack/Split Columns. The user interface for the Stack/Split Columns task opens.
  2. On the Data tab, select SASHELP.CLASSFIT as the input data set.
    Here are the Name, Sex, Age, Height, and Weight variables in the Sashelp.Classfit data set:
    SASHELP.CLASSFIT Data Set Before Running the Task
  3. From the Method drop-down list, select Stack columns.
  4. In the Columns to stack role, assign the lowermean and uppermean variables.
  5. On the Output tab, enter CLM as the name of the new column.
  6. Assign these variables to the Include other variables in output data set role.
    • Name
    • Sex
    • Age
    • Height
    • Weight
    • predict
  7. To run the task, click Submit SAS Code.
The results contain three new variables: _Case_, _Level_, and CLM. The _Case_ variable contains the case identifier. A case is the data for an individual student. The _Level_ variable contains the names of the stacked columns. The new CLM variable contains the value of the lower mean or upper mean.
Output Data for the Stack Column Task

Create a Stacked Column

To create a stacked column:
  1. After you select your input data source, select Stack columns from the Method drop-down list.
  2. Assign variables to these roles:
    Role
    Description
    Roles
    Column to stack
    specifies columns that contain the values that you want to stack.
    Additional Roles
    Group analysis by
    specifies the variable to use to form BY groups.
  3. On the Output tab, set these options:
    Option Name
    Description
    Output Data Set
    Name of new column
    specifies the name of the new column that contains all the stacked values.
    Case Identifier
    Case identifier
    specifies the name of the new column that contains the values that identify a particular case. You can select whether the task creates a case variable, or you can select identifier variables from the input data set.
    New column name of case identifier
    specifies the name of the new column that contains the values of the case identifier.
    Level Identifier
    Name of column containing levels of stacked columns
    specifies the name of the new column that contains the levels.
    Include other variables in output data set
    enables you to select other variables from the input data set that you want to include in the output data set.
    Show Output Data Set
    Show output data
    specifies whether to include the output data in the results that appear on the Results tab. You can include all or a subset of the output data. The task always creates the output data set that appears on the Output Data tab. This data set is also saved to the specified location.