Here is a script that should give you a leg up in solving your issue
Names Default To Here( 1 );
// build an example data table
dt = New Table( "Example",
add rows( 20 ),
New Column( "A",
character,
formula(
rand = Random Uniform( 0, 100 );
If(
rand >= 0 & rand <= 40, x = 1,
rand >= 40 & rand <= 60, x = 2,
rand >= 60 & rand <= 80, x = 3,
x = 4
);
"A" || Char( x );
)
),
New Column( "B",
character,
formula(
rand = Random Uniform( 0, 100 );
If(
rand >= 0 & rand <= 20, x = 1,
rand >= 20 & rand <= 60, x = 2,
rand >= 60 & rand <= 80, x = 3,
x = 4
);
"B" || Char( x );
)
),
New Column( "C",
character,
formula(
rand = Random Uniform( 0, 100 );
If(
rand >= 0 & rand <= 20, x = 1,
rand >= 20 & rand <= 40, x = 2,
rand >= 40 & rand <= 80, x = 3,
x = 4
);
"C" || Char( x );
)
),
New Column( "D",
character,
formula(
rand = Random Uniform( 0, 100 );
If(
rand >= 0 & rand <= 20, x = 1,
rand >= 20 & rand <= 40, x = 2,
rand >= 40 & rand <= 60, x = 3,
x = 4
);
"D" || Char( x );
)
)
);
// The JSL below is the code that does the actual work
Data Table( "Example" ) << Stack(
columns( :A, :B, :C, ),
Source Label Column( "Column" ),
Stacked Data Column( "Data" ),
Output Table( "Stacked" )
);
dtS = Data Table( "Stacked" ) << Summary(
Group( :Column, :Data ),
Freq( "None" ),
Weight( "None" ),
output table name( "Summary" )
);
dtS << select where( :N Rows[Row()] == col max(:N Rows, :Data));
dtS << new column("Mode", formula(
Col Max(:N Rows, :Column)
));
dtS << select where( :N Rows == :Mode);
dtS << invert row selection << delete rows;
eval(parse(
"dt << Select Where (dt:\!"" || dts:column[1] || "\!"n == dtS:Data[1] );"));
For( i=2,i<=NRows(dtS), i++,
eval(parse(
"dt << Select Where (dt:\!"" || dts:column[i] || "\!"n == dtS:Data[i] , current selection(\!"extend\!"));"));
);
dtFinal = dt << Subset( selected columns(0), selected rows(1), output table("Final"));
Jim