<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: A Better Way to Do a For Loop with Two Lists? in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/A-Better-Way-to-Do-a-For-Loop-with-Two-Lists/m-p/630318#M82847</link>
    <description>&lt;P&gt;I'd guess you're right about that is what they want to do.&amp;nbsp; Adding onto it, even if it were dynamic you could do something like.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names default to here( 1 );
dt = open("$SAMPLE_DATA\Big Class.jmp");
col_dict = ["height"=&amp;gt;{13, 128, 60}, 
	"weight"=&amp;gt;{95, 123, 79, 105}, 
	"age"=&amp;gt;{17}
];
//create an orexpression 
or_expr = Expr(OR());
for(key = col_dict&amp;lt;&amp;lt;First, !isempty(key), key = col_dict&amp;lt;&amp;lt;next(key), 
	// for each column just add another contains(values, col) statement
	insert into(or_expr, EvalExpr(Contains(Expr(col_dict[key]), Column(Expr(key))[])));
);

final_expr = EvalExpr(dt &amp;lt;&amp;lt; SelectWhere(Expr(nameexpr(or_expr))));
print(nameexpr(final_expr)); // just to show the final output it's actually running
Eval(final_expr);&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 09 May 2023 18:58:04 GMT</pubDate>
    <dc:creator>vince_faller</dc:creator>
    <dc:date>2023-05-09T18:58:04Z</dc:date>
    <item>
      <title>A Better Way to Do a For Loop with Two Lists?</title>
      <link>https://community.jmp.com/t5/Discussions/A-Better-Way-to-Do-a-For-Loop-with-Two-Lists/m-p/628722#M82701</link>
      <description>&lt;P&gt;Noob here.&amp;nbsp; I have a nested for loop that uses two lists that selects specific diagnostic codes from multiple diagnosis columns.&amp;nbsp; It works, but I was wondering if there's a better way to code it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;ColumnList = {"DIAGNOSIS_1", "DIAGNOSIS_2", "DIAGNOSIS_3"};
ValueList = {"E871","O480","J449"};*/
For( i = 1, i &amp;lt;= N Items( ColumnList ), i++, 
	ColumnItem = ColumnList[i];
	Eval(
		Eval Expr(
			As Constant( col = As Name( Expr( ColumnItem ) ) );
			For( j = 1, j &amp;lt;= N Items( ValueList ), j++, 
				ValueItem = ValueList[j];
				all_ip &amp;lt;&amp;lt; select where( As Column( col ) == ValueItem, Current Selection( "extend" ) );
			);
		)
	);
);

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 09 Jun 2023 16:09:20 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/A-Better-Way-to-Do-a-For-Loop-with-Two-Lists/m-p/628722#M82701</guid>
      <dc:creator>Pertussic</dc:creator>
      <dc:date>2023-06-09T16:09:20Z</dc:date>
    </item>
    <item>
      <title>Re: A Better Way to Do a For Loop with Two Lists?</title>
      <link>https://community.jmp.com/t5/Discussions/A-Better-Way-to-Do-a-For-Loop-with-Two-Lists/m-p/628737#M82702</link>
      <description>&lt;P&gt;Maybe this is what you are trying to do.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Open( "$sample_data/big class.jmp" );
ColumnList = {"height", "weight", "age"};
ValueList = {13, 128, 60};
For Each( {col}, ColumnList,
	For Each( {ValueItem}, ValueList,
		dt &amp;lt;&amp;lt; select where( As Column( dt, col ) == ValueItem, Current Selection( "extend" ) )
	)
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or even this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Open( "$sample_data/big class.jmp" );
ColumnList = {:height, :weight, :age};
ValueList = {13, 128, 60};
For Each( {col}, ColumnList,
	For Each( {ValueItem}, ValueList, dt &amp;lt;&amp;lt; select where( col == ValueItem, Current Selection( "extend" ) ) )
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(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&amp;nbsp;where height or weight or age are 60. Just using it to try to match what I think you mean.)&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2023 01:01:01 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/A-Better-Way-to-Do-a-For-Loop-with-Two-Lists/m-p/628737#M82702</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2023-05-05T01:01:01Z</dc:date>
    </item>
    <item>
      <title>Re: A Better Way to Do a For Loop with Two Lists?</title>
      <link>https://community.jmp.com/t5/Discussions/A-Better-Way-to-Do-a-For-Loop-with-Two-Lists/m-p/628740#M82703</link>
      <description>&lt;P&gt;Or even this&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Open( "$sample_data/big class.jmp" );
ValueList = {13, 128, 60};
dt &amp;lt;&amp;lt; select where( Contains( ValueList, :height ) | Contains( ValueList, :weight ) | Contains( ValueList, :age ) );
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;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.&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2023 01:45:04 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/A-Better-Way-to-Do-a-For-Loop-with-Two-Lists/m-p/628740#M82703</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2023-05-05T01:45:04Z</dc:date>
    </item>
    <item>
      <title>Re: A Better Way to Do a For Loop with Two Lists?</title>
      <link>https://community.jmp.com/t5/Discussions/A-Better-Way-to-Do-a-For-Loop-with-Two-Lists/m-p/629290#M82751</link>
      <description>&lt;P&gt;Is For Each() only available in Pro?&amp;nbsp; I just have Basic and it doesn't work.&amp;nbsp; Or did I miss an update somewhere?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2023 21:13:45 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/A-Better-Way-to-Do-a-For-Loop-with-Two-Lists/m-p/629290#M82751</guid>
      <dc:creator>Pertussic</dc:creator>
      <dc:date>2023-05-05T21:13:45Z</dc:date>
    </item>
    <item>
      <title>Re: A Better Way to Do a For Loop with Two Lists?</title>
      <link>https://community.jmp.com/t5/Discussions/A-Better-Way-to-Do-a-For-Loop-with-Two-Lists/m-p/629302#M82752</link>
      <description>&lt;P&gt;regular JMP, since 16.&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2023 23:55:41 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/A-Better-Way-to-Do-a-For-Loop-with-Two-Lists/m-p/629302#M82752</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2023-05-05T23:55:41Z</dc:date>
    </item>
    <item>
      <title>Re: A Better Way to Do a For Loop with Two Lists?</title>
      <link>https://community.jmp.com/t5/Discussions/A-Better-Way-to-Do-a-For-Loop-with-Two-Lists/m-p/629783#M82789</link>
      <description>&lt;P&gt;Per Scripting Index in JMP 17: added in JMP 16 (JMP or JMP Pro)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="for.PNG" style="width: 958px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/52636i755243521E33A197/image-size/large?v=v2&amp;amp;px=999" role="button" title="for.PNG" alt="for.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 08 May 2023 10:05:35 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/A-Better-Way-to-Do-a-For-Loop-with-Two-Lists/m-p/629783#M82789</guid>
      <dc:creator>Mark_Bailey</dc:creator>
      <dc:date>2023-05-08T10:05:35Z</dc:date>
    </item>
    <item>
      <title>Re: A Better Way to Do a For Loop with Two Lists?</title>
      <link>https://community.jmp.com/t5/Discussions/A-Better-Way-to-Do-a-For-Loop-with-Two-Lists/m-p/629891#M82804</link>
      <description>&lt;P&gt;And that'd do it.&amp;nbsp; I'm still at 15.&amp;nbsp; I could have sworn I updated.&amp;nbsp; COVID's kept me busy.&lt;/P&gt;</description>
      <pubDate>Mon, 08 May 2023 16:58:32 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/A-Better-Way-to-Do-a-For-Loop-with-Two-Lists/m-p/629891#M82804</guid>
      <dc:creator>Pertussic</dc:creator>
      <dc:date>2023-05-08T16:58:32Z</dc:date>
    </item>
    <item>
      <title>Re: A Better Way to Do a For Loop with Two Lists?</title>
      <link>https://community.jmp.com/t5/Discussions/A-Better-Way-to-Do-a-For-Loop-with-Two-Lists/m-p/630318#M82847</link>
      <description>&lt;P&gt;I'd guess you're right about that is what they want to do.&amp;nbsp; Adding onto it, even if it were dynamic you could do something like.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names default to here( 1 );
dt = open("$SAMPLE_DATA\Big Class.jmp");
col_dict = ["height"=&amp;gt;{13, 128, 60}, 
	"weight"=&amp;gt;{95, 123, 79, 105}, 
	"age"=&amp;gt;{17}
];
//create an orexpression 
or_expr = Expr(OR());
for(key = col_dict&amp;lt;&amp;lt;First, !isempty(key), key = col_dict&amp;lt;&amp;lt;next(key), 
	// for each column just add another contains(values, col) statement
	insert into(or_expr, EvalExpr(Contains(Expr(col_dict[key]), Column(Expr(key))[])));
);

final_expr = EvalExpr(dt &amp;lt;&amp;lt; SelectWhere(Expr(nameexpr(or_expr))));
print(nameexpr(final_expr)); // just to show the final output it's actually running
Eval(final_expr);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 May 2023 18:58:04 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/A-Better-Way-to-Do-a-For-Loop-with-Two-Lists/m-p/630318#M82847</guid>
      <dc:creator>vince_faller</dc:creator>
      <dc:date>2023-05-09T18:58:04Z</dc:date>
    </item>
    <item>
      <title>Re: A Better Way to Do a For Loop with Two Lists?</title>
      <link>https://community.jmp.com/t5/Discussions/A-Better-Way-to-Do-a-For-Loop-with-Two-Lists/m-p/632374#M83084</link>
      <description>&lt;P&gt;Sorry for the delay; I had to update to 17.&amp;nbsp; And your code works perfectly!&amp;nbsp; Thank you.&lt;/P&gt;</description>
      <pubDate>Tue, 16 May 2023 20:47:20 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/A-Better-Way-to-Do-a-For-Loop-with-Two-Lists/m-p/632374#M83084</guid>
      <dc:creator>Pertussic</dc:creator>
      <dc:date>2023-05-16T20:47:20Z</dc:date>
    </item>
  </channel>
</rss>

