Here is an example of one way to do the processing to set the grade for each raw data row. I have it set to have an Example data table of 50,000, which on my 4 year olf Window's pc takes about 2 seconds to create the example data and then to set the grade for each row.
Names Default To Here( 1 );
// Create a sample standards table
dtStandard = New Table( "Standards",
Add Rows( 200 ),
New Column( "standards", formula( Random Integer( 93500, 1000000 ) ) )
);
dtStandard << run formulas;
dtStandard:standards << delete property( "formula" );
dtStandard << sort( by( :standards ), order( ascending ), replace table( 1 ) );
dtStandard << rerun formulas;
dtStandard << New Column( "grades", formula( Row() ) );
dtStandard:grades << delete property( "formula" );
// Create an example table
dt = New Table( "Example",
Add Rows( 50000 ),
New Column( "Raw Data", formula( Random Integer( 93500, 1000000 ) ) )
);
dt << run formulas;
dt:Raw Data << delete property( "formula" );
// Make sure the standards table has the same range as the example table
If( dtStandard:standards[1] > Col Min( dt:raw data ),
dtStandard:standards[1] = Col Min( dt:raw data )
);
If( dtStandard:standards[200] < Col Max( dt:raw data ),
dtStandard:standards[200] = Col Max( dt:raw data )
);
// Set the standard
// The code below is the actual code that performs the setting of the grade
// Create a column to hold the original row positions in the data table
dt << New Column( "OrigRow", formula( Row() ) );
dt:OrigRow << delete property( "formula" );
// Add the new grades column to the Example data
dt << New Column( "grade" );
// Sort the data in order of the raw data
dt << sort( by( :Raw Data ), order( ascending ), replace table( 1 ) );
For( i = 1, i <= N Rows( dt ), i++,
If( i == 1,
lkupRow = Max( dtStandard << get rows where( dtStandard:standards <= dt:Raw Data[i] ) )
);
While( dtStandard:standards[lkupRow] < dt:Raw Data[i], lkupRow = lkupRow + 1 );
dt:grade[i] = dtStandard:grades[lkupRow];
);
// Sort the data back to the original order
dt << sort( by( :OrigRow ), order( ascending ), replace table( 1 ) );
// Delete the origrow column
dt << delete columns( "OrigRow" );
Jim