A Better Way to Do a For Loop with Two Lists?Noob here. I have a nested for loop that uses two lists that selects specific diagnostic codes from multiple diagnosis columns. It works, but I was wondering if there's a better way to code it.
ColumnList = {"DIAGNOSIS_1", "DIAGNOSIS_2", "DIAGNOSIS_3"};
ValueList = {"E871","O480","J449"};*/
For( i = 1, i <= N Items( ColumnList ), i++,
ColumnItem = ColumnList[i];
Eval(
Eval Expr(
As Constant( col = As Name( Expr( ColumnItem ) ) );
For( j = 1, j <= N Items( ValueList ), j++,
ValueItem = ValueList[j];
all_ip << select where( As Column( col ) == ValueItem, Current Selection( "extend" ) );
);
)
);
);
Consumer and Market ResearchData AccessRe: A Better Way to Do a For Loop with Two Lists?Sorry for the delay; I had to update to 17. And your code works perfectly! Thank you.
Re: A Better Way to Do a For Loop with Two Lists?I'd guess you're right about that is what they want to do. Adding onto it, even if it were dynamic you could do something like.
Names default to here( 1 );
dt = open("$SAMPLE_DATA\Big Class.jmp");
col_dict = ["height"=>{13, 128, 60},
"weight"=>{95, 123, 79, 105},
"age"=>{17}
];
//create an orexpression
or_expr = Expr(OR());
for(key = col_dict<<FIRST></FIRST>Re: A Better Way to Do a For Loop with Two Lists?And that'd do it. I'm still at 15. I could have sworn I updated. COVID's kept me busy.
Re: A Better Way to Do a For Loop with Two Lists?Per Scripting Index in JMP 17: added in JMP 16 (JMP or JMP Pro)

Re: A Better Way to Do a For Loop with Two Lists?regular JMP, since 16.
Re: A Better Way to Do a For Loop with Two Lists?Is For Each() only available in Pro? I just have Basic and it doesn't work. Or did I miss an update somewhere?
Re: A Better Way to Do a For Loop with Two Lists?Or even this
dt = Open( "$sample_data/big class.jmp" );
ValueList = {13, 128, 60};
dt << select where( Contains( ValueList, :height ) | Contains( ValueList, :weight ) | Contains( ValueList, :age ) );
Just imagine that height, weight, and age were all the same units, similar to the diagnosis columns. I think this is what you want if the number of diagnosis columns will always be three.
Re: A Better Way to Do a For Loop with Two Lists?Maybe this is what you are trying to do.
dt = Open( "$sample_data/big class.jmp" );
ColumnList = {"height", "weight", "age"};
ValueList = {13, 128, 60};
For Each( {col}, ColumnList,
For Each( {ValueItem}, ValueList,
dt << select where( As Column( dt, col ) == ValueItem, Current Selection( "extend" ) )
)
);
or even this
dt = Open( "$sample_data/big class.jmp" );
ColumnList = {:height, :weight, :age};
ValueList = {13, 128, 60};
For Each( {col}, ColumnList,
For Each( {ValueItem}, ValueList, dt << select where( col == ValueItem, Current Selection( "extend" ) ) )
);
(It might make sense with your data, but with big class it doesn't make a lot of sense to select rows where height or weight or age are 13, or where height or weight or age are 128, or where height or weight or age are 60. Just using it to try to match what I think you mean.)