Splitting Columns

Example 1: Splitting the Height Column in the CLASSFIT Data Set

  1. In the Tasks section, expand the Data folder, and then 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.
    Tip
    If the data set is not available from the drop-down list, click Select a table icon. In the Choose a Table window, expand the library that contains the data set that you want to use. Select the data set for the example and click OK. The selected data set should now appear in the drop-down list.
    Here are the Name, Sex, Age, Height, and Weight columns in the Sashelp.Classfit data set:
    Subset of Sashelp.Classfit Data Set
  3. From the Method drop-down list, select Split a column.
  4. Assign columns to these roles:
    Role
    Column Name
    Column to split
    Age
    Case Identifier
    Height
    Level Identifier
    Sex
  5. Click the Output tab.
    • Clear the Use prefix check box.
    • Select the Select a variable that contains the names for the new variables check box, and assign Sex to the New column names role.
  6. To run the task, click Submit SAS Code Icon.
The resulting output data set contains three columns: Height, F, and M. From this output, you can see that one 11-year-old female has a height of 51.3 inches. No males are 51.3 inches. A 15-year-old female and a 15-year-old male are both 66.5 inches.
Resulting Work.Split Data Set

Example 2: Creating Multiple Split Columns

Using the Stack/Split Columns task, you can create multiple split columns.
  1. In SAS Studio, click New Options Icon and select New SAS Program.
  2. To create the multisplit data set, copy and paste this code onto the Program tab.
    data multisplit;
    input case level value1 name1 $ value2 name2 $;
    cards;
    1 1 1 L1 11 K1
    1 2 2 L2 22 K2
    1 3 3 L3 33 K3
    2 1 4 L1 44 K1
    2 2 5 L2 55 K2
    2 3 6 L3 66 K3
    ;
    
    To create the Work.Multisplit data set, click Submit SAS Code Icon.
  3. In the Tasks section, expand the Data folder, and then double-click Stack/Split Columns. The user interface for the Stack/Split Columns task opens.
  4. On the Data tab, select WORK.MULTISTACK as the input data set.
    Tip
    If the data set is not available from the drop-down list, click Select a table icon. In the Choose a Table window, expand the library that contains the data set that you want to use. Select the data set for the example and click OK. The selected data set should now appear in the drop-down list.
  5. Assign columns to these roles:
    Role
    Column Name
    Columns to split
    value1
    value2
    Case identifier
    case
    Level identifier
    level
  6. To run the task, click Submit SAS Code Icon.
Here is a subset of the output data set:
Work.Split0001 Output Data Set

Split a Column

To split a column:
  1. Select the input data source. To filter the input data source, click Filter Icon.
  2. Select Split a column from the Method drop-down list.
  3. Assign variables to these roles:
    Roles
    Description
    Roles
    Columns to split
    specifies the variable that contains the values that you want to split into multiple columns.
    Case identifier
    identifies the values that belong to a particular case.
    Level identifier
    identifies the levels of the column to split. Each new variable contains the values of one level of the level identifier.
    Additional Roles
    Group analysis by
    specifies the variable to use to form BY groups.
  4. On the Output tab, set these options:
    Option Name
    Description
    Construct New Variable Names
    Use prefix
    You can specify a prefix to use in constructing the names for the transposed variables in the output data set. When you use a prefix, the variable name begins with the prefix value and is followed by the number 1, 2, and so on. To create a variable name with the prefix and the value of the selected variable, select Select a variable that contains the names for the new variables.
    Select a variable that contains the names for the new variables
    The variable that you assign to the New column names role is used to name the new columns in the output data set.
    If you assigned two or more variables to the Columns to split role on the Data tab, you can select the column to use for each split variable.
    Show Output Data
    Show output data
    specifies whether to display the output data set on the Results tab. You can choose to display all of the data or a subset of the output data. The task always creates an output data set that appears on the Output Data tab. The output data is also saved as a SAS data set.