<?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: For Each Loop across multiple associative arrays in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/For-Each-Loop-across-multiple-associative-arrays/m-p/718141#M90017</link>
    <description>&lt;P&gt;Thanks for the reply. As mentioned, it's not that I cannot easily extract the values. I just find it weird that for a single associative array it's also possible to reference the values using a nested list, but not across multiple arrays.&lt;/P&gt;</description>
    <pubDate>Mon, 22 Jan 2024 19:08:35 GMT</pubDate>
    <dc:creator>AlterEgo</dc:creator>
    <dc:date>2024-01-22T19:08:35Z</dc:date>
    <item>
      <title>For Each Loop across multiple associative arrays</title>
      <link>https://community.jmp.com/t5/Discussions/For-Each-Loop-across-multiple-associative-arrays/m-p/718119#M90012</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm struggling with the syntax for a For Each loop across multiple associative arrays.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;q = ["q1"=&amp;gt;11, "q2"=&amp;gt;22, "q3"=&amp;gt;33];
w = ["w1"=&amp;gt;1111, "w2"=&amp;gt;2222, "w3"=&amp;gt;3333];&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;For single array, just for reference:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;For Each( {a, i}, q, Show( i, a ) ); // retrieves indices and keys
For Each( { {a, b}, i }, q, Show( i, a, b ) ); // retrieves indices, keys and values&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Analogously, across two arrays it works to some extent:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;For Each( {a, i}, Across( q, w ), show( i, a ) );&lt;BR /&gt;// retrieves indices and two-item lists of keys of both arrays:
i = 1;
a = {"q1", "w1"};
i = 2;
a = {"q2", "w2"};
i = 3;
a = {"q3", "w3"};&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Then drilling further:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;For Each( { {a, b}, i }, Across( q, w ), show( i, a, b ) );&lt;BR /&gt;// retrieves indices and keys of both arrays separately:
i = 1;
a = "q1";
b = "w1";
i = 2;
a = "q2";
b = "w2";
i = 3;
a = "q3";
b = "w3";&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;However, I want to get values also. I tried several variants of brace groupings and nothing works.&amp;nbsp;Drawing from the single array syntax this should be the most obvious one:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;For Each( { { {a, b}, {c, d} }, i }, Across( q, w ), show( i, a, b, c, d ) );&lt;BR /&gt;//&amp;nbsp;returns error:&lt;BR /&gt;argument value is invalid in access or evaluation of 'For Each' , Bad Argument( {a, b} ), For Each/*###*/({{{a, b}, &lt;BR /&gt;{c, d}}, i}, Across( q, w ), Show( i, a, b, c, d ))&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I RTFM-ed and RTFF-ed and couldn't find anything.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Of course I can do this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;For Each( { {a, b}, i }, Across( q, w ), show( i, a, b, q[a], w[b] ) );&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;but this is not the point. It's a matter of elegance.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas?&lt;/P&gt;</description>
      <pubDate>Mon, 22 Jan 2024 16:50:11 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/For-Each-Loop-across-multiple-associative-arrays/m-p/718119#M90012</guid>
      <dc:creator>AlterEgo</dc:creator>
      <dc:date>2024-01-22T16:50:11Z</dc:date>
    </item>
    <item>
      <title>Re: For Each Loop across multiple associative arrays</title>
      <link>https://community.jmp.com/t5/Discussions/For-Each-Loop-across-multiple-associative-arrays/m-p/718122#M90014</link>
      <description>&lt;P class="S3ArgText"&gt;&lt;A href="https://www.jmp.com/support/help/en/17.2/#page/jmp/conditional-and-logical-functions.shtml?os=win&amp;amp;source=application#ww10169967" target="_blank"&gt;https://www.jmp.com/support/help/en/17.2/#page/jmp/conditional-and-logical-functions.shtml?os=win&amp;amp;source=application#ww10169967&lt;/A&gt;&lt;/P&gt;
&lt;P class="S3ArgText"&gt;&lt;EM&gt;When specifying multiple containers using the &lt;SPAN class="code"&gt;Across()&lt;/SPAN&gt; keyword, the names list contains a list of names that refer to values in each container. The number of names in the first item in the names list must match the number of containers specified in the &lt;SPAN class="code"&gt;Across()&lt;/SPAN&gt; keyword.&lt;/EM&gt;&lt;/P&gt;
&lt;P class="S3ArgText"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="S3ArgText"&gt;And for associative array&lt;/P&gt;
&lt;P class="S3ArgText"&gt;&lt;EM&gt;For an &lt;SPAN class="Emphasis"&gt;associative array&lt;/SPAN&gt; container, the names list contains a two-item list of names and a name for the index of each item in the associative array.&lt;/EM&gt;&lt;/P&gt;
&lt;P class="S3ArgText"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="S3ArgText"&gt;So I think you have to go with something like you did suggest&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

aa1 = ["q1" =&amp;gt; 11, "q2" =&amp;gt; 22, "q3" =&amp;gt; 33];
aa2 = ["w1" =&amp;gt; 1111, "w2" =&amp;gt; 2222, "w3" =&amp;gt; 3333];

For Each({{key1, key2}, i}, Across(aa1, aa2),
	val1 = aa1[key1];
	val2 = aa2[key2];
	Print(Eval Insert("\!Ni = ^i^"));
	Print(Eval Insert("key1 = ^key1^, val1 = ^val1^"));
	Print(Eval Insert("key2 = ^key2^, val2 = ^val2^"));
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P class="S3ArgText"&gt;or maybe something like this (which also feels a bit weird)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

aa1 = ["q1" =&amp;gt; 11, "q2" =&amp;gt; 22, "q3" =&amp;gt; 33];
aa2 = ["w1" =&amp;gt; 1111, "w2" =&amp;gt; 2222, "w3" =&amp;gt; 3333];

For Each({{key1, key2, val1, val2}, i}, Across(aa1, aa2, aa1 &amp;lt;&amp;lt; get values, aa2 &amp;lt;&amp;lt; get values),
	Print(Eval Insert("\!Ni = ^i^"));
	Print(Eval Insert("key1 = ^key1^, val1 = ^val1^"));
	Print(Eval Insert("key2 = ^key2^, val2 = ^val2^"));
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P class="S3ArgText"&gt;There might be some syntax which should be used, but I have no idea what it could be and I agree something like this would most likely be the most obvious one&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;For Each({{{key1, val1}, {key2, val2}}, i}, Across(aa1, aa2), Show(i, key1, val1, key2, val2));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 22 Jan 2024 17:08:23 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/For-Each-Loop-across-multiple-associative-arrays/m-p/718122#M90014</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2024-01-22T17:08:23Z</dc:date>
    </item>
    <item>
      <title>Re: For Each Loop across multiple associative arrays</title>
      <link>https://community.jmp.com/t5/Discussions/For-Each-Loop-across-multiple-associative-arrays/m-p/718141#M90017</link>
      <description>&lt;P&gt;Thanks for the reply. As mentioned, it's not that I cannot easily extract the values. I just find it weird that for a single associative array it's also possible to reference the values using a nested list, but not across multiple arrays.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Jan 2024 19:08:35 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/For-Each-Loop-across-multiple-associative-arrays/m-p/718141#M90017</guid>
      <dc:creator>AlterEgo</dc:creator>
      <dc:date>2024-01-22T19:08:35Z</dc:date>
    </item>
  </channel>
</rss>

