Here is a script that will generate a stacked data table with 3 columns
Here is a script that will strip off the numerical number from the end of columns in a data table. Remember, when renaming columns, if the end result is a column name that is the same as a previous column's name, JMP will add a numeric value to make the new column name a unique name
Names Default To Here( 1 );
dt = Current Data Table();
For( i = 1, i <= N Cols( dt ), i++,
if(
is missing(
Num(
word(
-1,
Lowercase( Column( dt, i ) << get name )
,
"abcdefghijklmnopqrstuvwxyz;:, -_)(")
)
) == 0,
Column( dt, i ) <<
set name(
substr(
Column(dt,i)<<get name,
1,
Length( Column(dt,i)<<get name )
-Length(
Word(
-1,
Lowercase( Column(dt,i)<<get name ),
"abcdefghijklmnopqrstuvwxyz;:, -_)("
)
)
)
)
)
);
Names Default To Here( 1 );
dt = new table( "Example",
add rows( 10 ),
New Column( "Year2", formula( Random Integer( 1, 100 ) ) ),
New Column( "Year3", formula( Random Integer( 1, 100 ) ) ),
New Column( "Year4", formula( Random Integer( 1, 100 ) ) )
);
dtStack = Data Table( "Example" ) << Stack(
columns( :Year2, :Year3, :Year4 ),
Source Label Column( Column ),
Stacked Data Column( "Data" )
);
dtStack << New Column( "Year",
formula(
Num(
Word(
-1,
Lowercase( :Column ),
"abcdefghijklmnopqrstuvwxyz;:, -_)("
)
)
)
);
dtStack:Year << delete formula;
for each row(
:Column = substr(
:Column,
1,
Length( :Column ) - Length(
Word(
-1,
Lowercase( :Column ),
"abcdefghijklmnopqrstuvwxyz;:, -_)("
)
)
)
);
Jim