For the latest version of JMP Help, visit JMP.com/help.


Scripting Guide > Data Tables > Advanced Data Table Scripting > Split Values in a Stacked Data Table
Publication date: 11/29/2021

Split Values in a Stacked Data Table

Split() breaks a stacked column into several columns.

dt << Split(
	Split( columns ),
	// the column to split (required)
 
	Split by( column ),
	// the column to split by (required)
 
	Group(column),
	// split data within groups
 
	<Private>|<Invisible>,
	// resulting table is private or invisible
 
	Remaining Columns( Keep All | Drop All | Select( columns ) ),
	/* specify what to do with the remaining columns in the resulting table (Keep All by default) */
 
	<Copy formula( 0|1 )>,
	/* include column formulas from the source table in the resulting table (default is 1, true) */
 
	<Suppress formula evaluation( 0|1 )>,
	// stop any copied formulas from being evaluated (default is 1, true)
 
	Sort by Column Property,
	/* Sort the order of the output columns by the sort column property that is defined for the Split by column. */
 
	Output Table( "name" ));
	// generate the output to the table name specified

The following example reverses the previous example for Stack(), returning essentially the original table, except that the height and weight columns now appear in alphabetic order:

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt << Stack(
    Columns( :weight, :height ),
    Source Label Column( "ID" ),
    Stacked Data Column( "Y" ),
	 "Non-stacked columns"n( Keep( :age, :sex ) ),
    Output Table( "Stacked Table" )
);
dt2 = Data Table( "Stacked Table" );
dt2 << Split(
/* Split adds the column or columns that you want to split into several
new columns. */
	Split( Y ),
/* Split By adds the column whose values you want to use as the new column names, and as the basis for splitting the column. */
	Split By( ID ),
	Output Table( "Split" ) );

When multiple rows are mapped to the same row, only one value is kept.

dtabc = New Table( "abc",
 New Column( "Column 1", Character, Set Values( {"a", "a", "b", "b", "c"} )),
 New Column( "Column 2", Character, Set Values( {"x", "y", "x", "y", ""} )),
 New Column( "Column 3", Set Values( [1, 2, 3, 4, 5] ))
);
/* Split adds Column 3. You want to split the values (1, 2, 3..) into several new cols.
Split By adds Column 2. You want to use the values (x, y) as the new column names. */
dtabc << Split( Split By( :Column 2 ), Split( :Column 3 ));
Want more information? Have questions? Get answers in the JMP User Community (community.jmp.com).