Since you are worried about speed with large tables, you might create a 'lookup table' in a long format so there is one row per value and then use with Join or Update to do the lookup. Here is how that might look:
Names default to here( 1 );
d1 = Open( "$SAMPLE_DATA/Presidential Elections.jmp" );
d2 = New Table( "offset",
Add Rows( 8 ),
New Column( "State",
Character,
"Nominal",
Set Values(
{"Wyoming", "Montana", "Montana", "Alaska", "Wisconsin", "Nebraska", "Nevada", "Montana"}
)
),
New Column( "year",
Character,
"Ordinal",
Set Values( {"1988", "1988", "1988", "1992", "2000", "1992", "2004", "1980"} )
),
New Column( "data",
Numeric,
"Continuous",
Format( "Fixed Dec", 12, 1 ))
);
//Move data to a long format
d3 = d1 << Stack(
columns(
:Name( "1980" ),
:Name( "1984" ),
:Name( "1988" ),
:Name( "1992" ),
:Name( "1996" ),
:Name( "2000" ),
:Name( "2004" ),
:Name( "2008" ),
:Name( "2012" )
),
Source Label Column( "year" ),
Stacked Data Column( "data" )
);
d3 << Set Name( "Long format" );
d3:year << Set Modeling Type("Ordinal");
//'Lookup' the values:
d2 << Update( with(d3), Match Columns( :state=:state, :year=:year ), Add Columns from Update table( None ));
d3 << Close window;