<?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: Iterating through an Associative Array Using a For Loop with an Empty While Condition Not Working in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Iterating-through-an-Associative-Array-Using-a-For-Loop-with-an/m-p/384013#M63450</link>
    <description>&lt;P&gt;Here is some anonymized data (attached), in CSV format, including the relevant columns ID, Date, and a few others that I am interested in using.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Let me know if this helps or not. I am willing to continue the dialogue to help get to the answer for this question.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Mike&lt;/P&gt;</description>
    <pubDate>Mon, 10 May 2021 21:50:44 GMT</pubDate>
    <dc:creator>mostarr</dc:creator>
    <dc:date>2021-05-10T21:50:44Z</dc:date>
    <item>
      <title>Iterating through an Associative Array Using a For Loop with an Empty While Condition Not Working</title>
      <link>https://community.jmp.com/t5/Discussions/Iterating-through-an-Associative-Array-Using-a-For-Loop-with-an/m-p/381705#M63221</link>
      <description>&lt;P&gt;I got advice largely from&amp;nbsp;&lt;LI-MESSAGE title="Looping through an Associative Array's elements" uid="236892" url="https://community.jmp.com/t5/JSL-Cookbook/Looping-through-an-Associative-Array-s-elements/m-p/236892#U236892" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-tkb-thread lia-fa-icon lia-fa-tkb lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp;on how to iterate through associative arrays. My understanding is that the iterator iterates over the keys, not the values, but that you can easily access the values gives that you have the array.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My code is below.&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);
dt1 = Open("file path" );
dt2 = Open("file path 2");
Summarize(dt1, IDs = by(:ID)); //this finds all the unique IDs in the data file, which we will need
//First, populate the temporary data structure--associative array--from the dt1 data file which we will then copy over to the dt2 data file.
For (i=1, i&amp;lt;=N Items(IDs), i++,
	ID = IDs[i];
	temp_array = Associative Array ({"Val1","Val2","Val3"},{{},{},{}});
	For ( temp = temp_array &amp;lt;&amp;lt; First, Is Empty(temp_array[temp]), temp = temp_array &amp;lt;&amp;lt; Next(temp),//looping through temp_array's keys is clunky but done this way in JMP			
		query_date = dt1 &amp;lt;&amp;lt; Select Where (:"ID" == ID);
		Write(query_date);
		
		//etc not there yet because the above not working
	);
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The variable of interest at this point in my journey is query_date, which I need to proceed.&amp;nbsp; Problem is, as it is written, the inner loop doesn't run even once for some reason. The while condition in the loop should evaluate to True until I want the loop to terminate, so I have it set to&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Is Empty(temp_array[temp])&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;because&amp;nbsp; temp_array[temp] is the first value in the associative array, where temp is the first key, "Val1", and the value is {}. I guess an important question is: Does {} evaluate to True or False in Is Empty()? I can't even google this because {} are special characters which google doesn't process. So you can see why I'm confused.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have the rest of my script coded out already, and I am fairly confident it will work with minor errors at this point, so if I can get past this hurdle that would help a lot. The pseudocode is very clear in my mind and, as a new JMP JSL user, things are becoming clearer, which I am grateful for. Thank you all for your help!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Mike&lt;/P&gt;</description>
      <pubDate>Sat, 10 Jun 2023 23:29:42 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Iterating-through-an-Associative-Array-Using-a-For-Loop-with-an/m-p/381705#M63221</guid>
      <dc:creator>mostarr</dc:creator>
      <dc:date>2023-06-10T23:29:42Z</dc:date>
    </item>
    <item>
      <title>Re: Iterating through an Associative Array Using a For Loop with an Empty While Condition Not Working</title>
      <link>https://community.jmp.com/t5/Discussions/Iterating-through-an-Associative-Array-Using-a-For-Loop-with-an/m-p/381710#M63222</link>
      <description>&lt;P&gt;The for loop's condition needs to run while the key is not empty&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;For ( temp = temp_array &amp;lt;&amp;lt; First, ! Is Empty(temp), temp = temp_array &amp;lt;&amp;lt; Next(temp),&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The associative array's &amp;lt;&amp;lt;first and &amp;lt;&amp;lt;next methods either return a key (a string or a number) or the special empty() value when there are no more keys. That key (if not empty) can be used as an index to the associative array.&lt;/P&gt;&lt;P&gt;The ! is the &lt;EM&gt;not&lt;/EM&gt; operator.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;edit: you might want something like this&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;temp_array = Associative Array( {"Val1", "Val2", "Val3"}, {{1, 2}, {}, {3, 4, 5}} );
For( temp = temp_array &amp;lt;&amp;lt; First, !Is Empty( temp ), temp = temp_array &amp;lt;&amp;lt; Next( temp ),
	If( N Items( temp_array[temp] ) &amp;gt; 0,
		Write( "\!nkey=", temp, " has ", N Items( temp_array[temp] ), " elements" ),
		Write( "\!nkey=", temp, " has no elements" )
	)
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;STRONG&gt;key=Val1 has 2 elements&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;key=Val2 has no elements&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;key=Val3 has 3 elements&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 02 May 2021 01:52:35 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Iterating-through-an-Associative-Array-Using-a-For-Loop-with-an/m-p/381710#M63222</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2021-05-02T01:52:35Z</dc:date>
    </item>
    <item>
      <title>Re: Iterating through an Associative Array Using a For Loop with an Empty While Condition Not Working</title>
      <link>https://community.jmp.com/t5/Discussions/Iterating-through-an-Associative-Array-Using-a-For-Loop-with-an/m-p/381723#M63223</link>
      <description>&lt;P&gt;I am not understanding why you are using an Associative Array?&amp;nbsp; Can you expand on what you envisioning the loop you are attempting to execute is supposed to do?&lt;/P&gt;
&lt;P&gt;IsEmpty() is a function that returns a 1 if the script does not know what the referenced item is, and a 0 when the referenced item has been used in the script prior to the IsEmpty() execution.&lt;/P&gt;
&lt;P&gt;Therefore:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;a={};
isEmpty(s);
// returns 0 since  a  has been referenced prior in the script
isEmpty(b);
// returns 1 since JMP has not seen the variable b before&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Concerning&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;query_date = dt1 &amp;lt;&amp;lt; Select Where (:"ID" == ID);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The Select Where() performs an action, but does not return anything.&amp;nbsp; Therefore query_date has no value.&amp;nbsp; What Select Where() does, is to set the Selected Row State to "On" for all of the rows in the data table that meet the selection criteria.&amp;nbsp; If more than one row in the data table has the value of ID multiple rows will be selected.&amp;nbsp; Perhaps what you are looking for is the value of query date for the selected row.&amp;nbsp; You can get the row numbers of the selected rows&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt1 &amp;lt;&amp;lt; select where( :ID == ID );
theRows = dt1 &amp;lt;&amp;lt; get selected rows;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It returns a matrix of the row numbers, not a scaler.&amp;nbsp; Therefore, to get the query_date, you have to reference the subscript.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt1 &amp;lt;&amp;lt; select where( :ID == ID );
theRows = dt1 &amp;lt;&amp;lt; get selected rows;
query_date = dt1:query_date[ theRows[1] ];&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;A simpler form, not requiring the selection step would be to use Get Rows Where().&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;query_date = dt1:query_date[ dt1 &amp;lt;&amp;lt; get rows where( :ID == ID )[1] ];&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I hope I am helping and not confusing.&amp;nbsp; Please continue asking your questions.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 02 May 2021 03:05:31 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Iterating-through-an-Associative-Array-Using-a-For-Loop-with-an/m-p/381723#M63223</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2021-05-02T03:05:31Z</dc:date>
    </item>
    <item>
      <title>Re: Iterating through an Associative Array Using a For Loop with an Empty While Condition Not Working</title>
      <link>https://community.jmp.com/t5/Discussions/Iterating-through-an-Associative-Array-Using-a-For-Loop-with-an/m-p/381838#M63241</link>
      <description>Thank you, Jim. That was nice of you for the quick response. I appreciate it. Give me a bit of time to parse all of this again, it's the weekend.&lt;BR /&gt;&lt;BR /&gt;Mike</description>
      <pubDate>Mon, 03 May 2021 03:04:33 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Iterating-through-an-Associative-Array-Using-a-For-Loop-with-an/m-p/381838#M63241</guid>
      <dc:creator>mostarr</dc:creator>
      <dc:date>2021-05-03T03:04:33Z</dc:date>
    </item>
    <item>
      <title>Re: Iterating through an Associative Array Using a For Loop with an Empty While Condition Not Working</title>
      <link>https://community.jmp.com/t5/Discussions/Iterating-through-an-Associative-Array-Using-a-For-Loop-with-an/m-p/381936#M63251</link>
      <description>&lt;P&gt;Thanks for the reply, Jim. One thing: I do not understand&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;query_date = dt1:query_date[ theRows[1] ];&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;as query_date is not yet instantiated.&lt;/P&gt;&lt;P&gt;Is this a typo (supposed to be a different variable)?&lt;/P&gt;&lt;P&gt;The Log also throws an error here:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Scoped data table access requires a data table column or variable in access or evaluation of 'dt_ld4:query_date' , dt_ld4:query_date/*###*/&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I would normally figure this out on my own but this problem is proving surprisingly challenging so I'm not entirely sure.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a bunch,&lt;/P&gt;&lt;P&gt;Mike&lt;/P&gt;</description>
      <pubDate>Mon, 03 May 2021 17:07:03 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Iterating-through-an-Associative-Array-Using-a-For-Loop-with-an/m-p/381936#M63251</guid>
      <dc:creator>mostarr</dc:creator>
      <dc:date>2021-05-03T17:07:03Z</dc:date>
    </item>
    <item>
      <title>Re: Iterating through an Associative Array Using a For Loop with an Empty While Condition Not Working</title>
      <link>https://community.jmp.com/t5/Discussions/Iterating-through-an-Associative-Array-Using-a-For-Loop-with-an/m-p/381938#M63253</link>
      <description>&lt;P&gt;Hi Craige. This seems to work. Thank you very much.&lt;/P&gt;&lt;P&gt;Michael&lt;/P&gt;</description>
      <pubDate>Mon, 03 May 2021 17:08:34 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Iterating-through-an-Associative-Array-Using-a-For-Loop-with-an/m-p/381938#M63253</guid>
      <dc:creator>mostarr</dc:creator>
      <dc:date>2021-05-03T17:08:34Z</dc:date>
    </item>
    <item>
      <title>Re: Iterating through an Associative Array Using a For Loop with an Empty While Condition Not Working</title>
      <link>https://community.jmp.com/t5/Discussions/Iterating-through-an-Associative-Array-Using-a-For-Loop-with-an/m-p/381968#M63254</link>
      <description>&lt;P&gt;OK......I was guessing.&amp;nbsp; You indicated that you needed to find the query_date, and it appeared that it had to do with your Select Where().&amp;nbsp; So I guessed that in your data table, there is a column called query_date, and the Select Where() or Get Rows Where(), would return the row that has the desired query date.&amp;nbsp; And apparently I guessed wrong as to where the query date can be found.&lt;/P&gt;</description>
      <pubDate>Mon, 03 May 2021 17:43:17 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Iterating-through-an-Associative-Array-Using-a-For-Loop-with-an/m-p/381968#M63254</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2021-05-03T17:43:17Z</dc:date>
    </item>
    <item>
      <title>Re: Iterating through an Associative Array Using a For Loop with an Empty While Condition Not Working</title>
      <link>https://community.jmp.com/t5/Discussions/Iterating-through-an-Associative-Array-Using-a-For-Loop-with-an/m-p/382054#M63269</link>
      <description>&lt;P&gt;I'm running&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt1 &amp;lt;&amp;lt; select where( :ID == ID );
theRows = dt1 &amp;lt;&amp;lt; get selected rows;
Write(theRows);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;just to check if selecting theRows is working, and it doesn't look like we're even getting that far, though. It prints:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;[](0, 1)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;where it should be printing a very comprehensive row (upward of 20 columns) from the data table for each iteration through the loop. I have no idea what is going on.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To try to help answer your implicit question, theRows is just a temporary variable to find the rows that result from the ID column value matching the value specified in the loop (there may be multiple rows of this nature due to multiple copies of ID).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I realize this is confusing... but that's sort of why I'm struggling, too.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance,&lt;/P&gt;&lt;P&gt;Mike&lt;/P&gt;</description>
      <pubDate>Mon, 03 May 2021 20:45:36 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Iterating-through-an-Associative-Array-Using-a-For-Loop-with-an/m-p/382054#M63269</guid>
      <dc:creator>mostarr</dc:creator>
      <dc:date>2021-05-03T20:45:36Z</dc:date>
    </item>
    <item>
      <title>Re: Iterating through an Associative Array Using a For Loop with an Empty While Condition Not Working</title>
      <link>https://community.jmp.com/t5/Discussions/Iterating-through-an-Associative-Array-Using-a-For-Loop-with-an/m-p/382103#M63277</link>
      <description>can you provide a sample data table?</description>
      <pubDate>Tue, 04 May 2021 02:05:52 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Iterating-through-an-Associative-Array-Using-a-For-Loop-with-an/m-p/382103#M63277</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2021-05-04T02:05:52Z</dc:date>
    </item>
    <item>
      <title>Re: Iterating through an Associative Array Using a For Loop with an Empty While Condition Not Working</title>
      <link>https://community.jmp.com/t5/Discussions/Iterating-through-an-Associative-Array-Using-a-For-Loop-with-an/m-p/382220#M63290</link>
      <description>&lt;P&gt;You will get the scoping error message if your variable and column name are the same.&amp;nbsp; For example you have a column and a variable named ID.&amp;nbsp; Also query_date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Keep your column names (easier), and change your variable names.&amp;nbsp; E.g. :ID and one_id, :query_date and one_query_date.&lt;/P&gt;</description>
      <pubDate>Tue, 04 May 2021 14:11:32 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Iterating-through-an-Associative-Array-Using-a-For-Loop-with-an/m-p/382220#M63290</guid>
      <dc:creator>pmroz</dc:creator>
      <dc:date>2021-05-04T14:11:32Z</dc:date>
    </item>
    <item>
      <title>Re: Iterating through an Associative Array Using a For Loop with an Empty While Condition Not Working</title>
      <link>https://community.jmp.com/t5/Discussions/Iterating-through-an-Associative-Array-Using-a-For-Loop-with-an/m-p/383989#M63446</link>
      <description>&lt;P&gt;Yes, give me a moment. I'll have to anonymize all the data and identifiers real quick...&lt;/P&gt;&lt;P&gt;Mike&lt;/P&gt;</description>
      <pubDate>Mon, 10 May 2021 21:36:21 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Iterating-through-an-Associative-Array-Using-a-For-Loop-with-an/m-p/383989#M63446</guid>
      <dc:creator>mostarr</dc:creator>
      <dc:date>2021-05-10T21:36:21Z</dc:date>
    </item>
    <item>
      <title>Re: Iterating through an Associative Array Using a For Loop with an Empty While Condition Not Working</title>
      <link>https://community.jmp.com/t5/Discussions/Iterating-through-an-Associative-Array-Using-a-For-Loop-with-an/m-p/384013#M63450</link>
      <description>&lt;P&gt;Here is some anonymized data (attached), in CSV format, including the relevant columns ID, Date, and a few others that I am interested in using.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Let me know if this helps or not. I am willing to continue the dialogue to help get to the answer for this question.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Mike&lt;/P&gt;</description>
      <pubDate>Mon, 10 May 2021 21:50:44 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Iterating-through-an-Associative-Array-Using-a-For-Loop-with-an/m-p/384013#M63450</guid>
      <dc:creator>mostarr</dc:creator>
      <dc:date>2021-05-10T21:50:44Z</dc:date>
    </item>
  </channel>
</rss>

