Try something like this:
// Create a test table
dt = New Table( "Sample Measurements", Add Rows( 13 ),
New Column( "Sample", Character, Nominal, Set Values(
{"A", "A", "A", "A", "A", "B", "B", "B", "C", "C", "C", "C", "C"} ) ),
New Column( "Measurement", Numeric, Continuous, Format( "Best", 12 ),
Set Values( [65, 76, 23, 43, 67, 65, 546, 34, 64, 76, 32, 67, 88] )
),
);
// Add a random column
dt << New Column( "Random Value", Numeric, Continuous, Format( "Best", 12 ),
Formula( Random Uniform() ) );
// sort
dt << sort(replace table, by(:Sample, :Random Value));
// Add a sequence column
dt << new column("Sequence", numeric, continuous);
// Add sequence values
old_value = "XYZZ";
for (i = 1, i <= nrows(dt), i++,
sample_value = dt:sample[i];
if (sample_value != old_value,
old_value = sample_value;
k = 1;
);
dt:sequence[i] = k;
k++;
);