<?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: JSL - missing last value of the column when filled using a list in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/JSL-missing-last-value-of-the-column-when-filled-using-a-list/m-p/486374#M73038</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I really would avoid a construction like this. Looking at the formula in that table you can see that there is a problem. You run into scoping problems (using a list defined outside in a formula), and you try to write the column itself within the formula in the column. Didn't know that JMP would let us ...&lt;/P&gt;
&lt;P&gt;However I can reproduce your problem, but not exactly explain why.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So my proposal would be to loop outside like shown in the script below, it's much more transparent.&lt;/P&gt;
&lt;P&gt;The loc() function gives you the position (index) in the list.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another way would be to generate a table from your ID_LIST and Vessel_LIST,&lt;/P&gt;
&lt;P&gt;and join that table to the table with reference dt.&lt;/P&gt;
&lt;P&gt;&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 );

ID_List = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24",
"25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48"};

Vessel_List = {"CS1-1", "CS1-2", "CS1-3", "CS1-4", "CS1-5", "CS1-6", "CS1-7", "CS1-8", "CS1-9", "CS1-10", "CS1-11", "CS1-12", "CS2-1", "CS2-2",
"CS2-3", "CS2-4", "CS2-5", "CS2-6", "CS2-7", "CS2-8", "CS2-9", "CS2-10", "CS2-11", "CS2-12", "CS3-1", "CS3-2", "CS3-3", "CS3-4", "CS3-5", "CS3-6",
"CS3-7", "CS3-8", "CS3-9", "CS3-10", "CS3-11", "CS3-12", "CS4-1", "CS4-2", "CS4-3", "CS4-4", "CS4-5", "CS4-6", "CS4-7", "CS4-8", "CS4-9", "CS4-10",
"CS4-11", "CS4-12"};

Show( N Items( ID_LIST ) );
Show( N Items( Vessel_LIST ) );

dt = New Table( "test", add rows( 48 ), New Column( "Vessel ID ViCell", Character, Nominal, set values( Vessel_list ) ) );
N = N Rows( dt );

dt &amp;lt;&amp;lt; New Column( "row", "Numeric", "Continuous", Formula( For( i = 1, i &amp;lt;= N, i++, Column( dt, "row" )[i] = i ) ) );
dt &amp;lt;&amp;lt; New Column( "Vessel NB",
	"Numeric",
	"Continuous",
	Formula(
		For( i = 1, i &amp;lt; N + 1, i++,
			r = dt &amp;lt;&amp;lt; getRowsWhere( :Vessel ID ViCell == Vessel_List[i] );
			Column( dt, "Vessel NB" )[r] = ID_List[i];
		)
	)
);

// My proposal: run the loop outside, as the lists are outside, too
dt &amp;lt;&amp;lt; New Column( "Vessel NB 2", "Numeric", "Continuous" );
For Each Row( dt, :Vessel NB 2 = ID_LIST[Loc( Vessel_LIST, :Vessel ID ViCell )[1]] );&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 12 May 2022 17:52:42 GMT</pubDate>
    <dc:creator>Georg</dc:creator>
    <dc:date>2022-05-12T17:52:42Z</dc:date>
    <item>
      <title>JSL - missing last value of the column when filled using a list</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-missing-last-value-of-the-column-when-filled-using-a-list/m-p/486230#M73022</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;When I am running a formula to assign one element from a list in a column for rows where an element of another list is displayed in another column, I encounter an unexpected issue : I am missing the value of the last row.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;ID_List = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48"};

Vessel_List = {"CS1-1", "CS1-2", "CS1-3", "CS1-4", "CS1-5", "CS1-6", "CS1-7", "CS1-8", "CS1-9", "CS1-10", "CS1-11", "CS1-12", "CS2-1", "CS2-2", "CS2-3", "CS2-4", "CS2-5", "CS2-6", "CS2-7", "CS2-8", "CS2-9", "CS2-10", "CS2-11", "CS2-12", "CS3-1", "CS3-2", "CS3-3", "CS3-4", "CS3-5", "CS3-6", "CS3-7", "CS3-8", "CS3-9", "CS3-10", "CS3-11", "CS3-12", "CS4-1", "CS4-2", "CS4-3", "CS4-4", "CS4-5", "CS4-6", "CS4-7", "CS4-8", "CS4-9", "CS4-10", "CS4-11", "CS4-12"};

dt &amp;lt;&amp;lt; New Column( "Vessel NB",
  "Numeric",
  "Continuous",
   Formula(
	For( i = 1, i &amp;lt; N+1, i++,
		r= dt&amp;lt;&amp;lt;getRowsWhere( :Vessel ID ViCell == Vessel_List[i]);
		Column(dt, "Vessel NB")[r] = ID_List[i];	
	 ));
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Here is how it looks like&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="Starwatcher_0-1652350424986.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/42389iFA821FDCB087F80D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Starwatcher_0-1652350424986.png" alt="Starwatcher_0-1652350424986.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I encountered the issue in multiple fields where I do the same exercise.&lt;/P&gt;&lt;P&gt;I found a workaround by taking the previous value (that I know is the same as I sorted the table).&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;// change data type of Vessel Nb to numeric continuous
Column("Vessel NB") &amp;lt;&amp;lt; delete formula;
Column("Vessel NB") &amp;lt;&amp;lt; unlock;	
Column("Vessel NB")&amp;lt;&amp;lt; data type(numeric)&amp;lt;&amp;lt;format("Best", 12) &amp;lt;&amp;lt;modeling type(continuous);

// bandaid solution : get previous Vessel number value to fill last line missing value
Nr=N Rows (dt);
Column(dt, "Vessel NB")[Nr] =Column(dt, "Vessel NB")[Nr-1];&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;However, while this workaround worked for my first table, when working on a second table I get the following message and don't manage to solve the issue.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Starwatcher_1-1652351433818.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/42390iC85C775332C9998F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Starwatcher_1-1652351433818.png" alt="Starwatcher_1-1652351433818.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I don't understand why I get this message whereas I clearly just created a column that is containing a formula and appears as locked.&lt;/P&gt;&lt;P&gt;Would you have a suggestion on how to solve this and why this occured in the first place?&lt;/P&gt;&lt;P&gt;Thank you in advance&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;NB : I am using JMP 16&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 16:59:04 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-missing-last-value-of-the-column-when-filled-using-a-list/m-p/486230#M73022</guid>
      <dc:creator>Starwatcher</dc:creator>
      <dc:date>2023-06-09T16:59:04Z</dc:date>
    </item>
    <item>
      <title>Re: JSL - missing last value of the column when filled using a list</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-missing-last-value-of-the-column-when-filled-using-a-list/m-p/486374#M73038</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I really would avoid a construction like this. Looking at the formula in that table you can see that there is a problem. You run into scoping problems (using a list defined outside in a formula), and you try to write the column itself within the formula in the column. Didn't know that JMP would let us ...&lt;/P&gt;
&lt;P&gt;However I can reproduce your problem, but not exactly explain why.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So my proposal would be to loop outside like shown in the script below, it's much more transparent.&lt;/P&gt;
&lt;P&gt;The loc() function gives you the position (index) in the list.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another way would be to generate a table from your ID_LIST and Vessel_LIST,&lt;/P&gt;
&lt;P&gt;and join that table to the table with reference dt.&lt;/P&gt;
&lt;P&gt;&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 );

ID_List = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24",
"25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48"};

Vessel_List = {"CS1-1", "CS1-2", "CS1-3", "CS1-4", "CS1-5", "CS1-6", "CS1-7", "CS1-8", "CS1-9", "CS1-10", "CS1-11", "CS1-12", "CS2-1", "CS2-2",
"CS2-3", "CS2-4", "CS2-5", "CS2-6", "CS2-7", "CS2-8", "CS2-9", "CS2-10", "CS2-11", "CS2-12", "CS3-1", "CS3-2", "CS3-3", "CS3-4", "CS3-5", "CS3-6",
"CS3-7", "CS3-8", "CS3-9", "CS3-10", "CS3-11", "CS3-12", "CS4-1", "CS4-2", "CS4-3", "CS4-4", "CS4-5", "CS4-6", "CS4-7", "CS4-8", "CS4-9", "CS4-10",
"CS4-11", "CS4-12"};

Show( N Items( ID_LIST ) );
Show( N Items( Vessel_LIST ) );

dt = New Table( "test", add rows( 48 ), New Column( "Vessel ID ViCell", Character, Nominal, set values( Vessel_list ) ) );
N = N Rows( dt );

dt &amp;lt;&amp;lt; New Column( "row", "Numeric", "Continuous", Formula( For( i = 1, i &amp;lt;= N, i++, Column( dt, "row" )[i] = i ) ) );
dt &amp;lt;&amp;lt; New Column( "Vessel NB",
	"Numeric",
	"Continuous",
	Formula(
		For( i = 1, i &amp;lt; N + 1, i++,
			r = dt &amp;lt;&amp;lt; getRowsWhere( :Vessel ID ViCell == Vessel_List[i] );
			Column( dt, "Vessel NB" )[r] = ID_List[i];
		)
	)
);

// My proposal: run the loop outside, as the lists are outside, too
dt &amp;lt;&amp;lt; New Column( "Vessel NB 2", "Numeric", "Continuous" );
For Each Row( dt, :Vessel NB 2 = ID_LIST[Loc( Vessel_LIST, :Vessel ID ViCell )[1]] );&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 May 2022 17:52:42 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-missing-last-value-of-the-column-when-filled-using-a-list/m-p/486374#M73038</guid>
      <dc:creator>Georg</dc:creator>
      <dc:date>2022-05-12T17:52:42Z</dc:date>
    </item>
    <item>
      <title>Re: JSL - missing last value of the column when filled using a list</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-missing-last-value-of-the-column-when-filled-using-a-list/m-p/486428#M73040</link>
      <description>&lt;P&gt;I am guessing a bit, but I believe you are doing a lot of work that is not required to get to your final answer.&amp;nbsp; Additionally, you are using values within your formats that are not native to the format.&amp;nbsp; That is, if you save your data table after running the format, quit your JMP session, start up a new JMP session and open your saved data table, the formula will error out.&amp;nbsp; The variables of "n", "Vessel_List" and "ID_Vessel" will no longer be defined in your new JMP session.&amp;nbsp; Therefore, the format will no longer run.&lt;/P&gt;
&lt;P&gt;Could the below formula do what you want?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt &amp;lt;&amp;lt; New Column( "Vessel NB",
	"Numeric",
	"Continuous",
	Formula(
		currVessel = :Vessel ID ViCell;
		r = Current Data Table() &amp;lt;&amp;lt; Get Rows Where( :Vessel ID ViCell == curVessel );
		r[n items(r)];
	)
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 May 2022 19:54:59 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-missing-last-value-of-the-column-when-filled-using-a-list/m-p/486428#M73040</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2022-05-12T19:54:59Z</dc:date>
    </item>
    <item>
      <title>Re: JSL - missing last value of the column when filled using a list</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-missing-last-value-of-the-column-when-filled-using-a-list/m-p/487153#M73098</link>
      <description>&lt;P&gt;Thank you Georg! This is working like a charm!&lt;/P&gt;</description>
      <pubDate>Mon, 16 May 2022 14:24:15 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-missing-last-value-of-the-column-when-filled-using-a-list/m-p/487153#M73098</guid>
      <dc:creator>Starwatcher</dc:creator>
      <dc:date>2022-05-16T14:24:15Z</dc:date>
    </item>
    <item>
      <title>Re: JSL - missing last value of the column when filled using a list</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-missing-last-value-of-the-column-when-filled-using-a-list/m-p/487154#M73099</link>
      <description>&lt;P&gt;Hello Jim,&lt;/P&gt;&lt;P&gt;what I am trying to do is to "translate" the vessel ID into a vessel number. There are more than 48 rows, so I don't think your solution would help.&lt;/P&gt;&lt;P&gt;Thank you anyway&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Céline&lt;/P&gt;</description>
      <pubDate>Mon, 16 May 2022 14:26:20 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-missing-last-value-of-the-column-when-filled-using-a-list/m-p/487154#M73099</guid>
      <dc:creator>Starwatcher</dc:creator>
      <dc:date>2022-05-16T14:26:20Z</dc:date>
    </item>
    <item>
      <title>Re: JSL - missing last value of the column when filled using a list</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-missing-last-value-of-the-column-when-filled-using-a-list/m-p/487181#M73100</link>
      <description>&lt;P&gt;I had a typo in my previous post.&amp;nbsp; Try the below JSL and see if you get the same results as&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/9474"&gt;@Georg&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt=current data table();
dt &amp;lt;&amp;lt; New Column( "Vessel NB 3",
	"Numeric",
	"Continuous",
	Formula(
		currVessel = :Vessel ID ViCell;
		r = Current Data Table() &amp;lt;&amp;lt; Get Rows Where( :Vessel ID ViCell == currVessel );
		try(r[n items(r)]);
	)
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 May 2022 14:45:22 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-missing-last-value-of-the-column-when-filled-using-a-list/m-p/487181#M73100</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2022-05-16T14:45:22Z</dc:date>
    </item>
  </channel>
</rss>

