<?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 How do I get items from a list to output a value from another list ? in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-do-I-get-items-from-a-list-to-output-a-value-from-another/m-p/561711#M77480</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;New to JMP and have searched and read loads of help and going around in circles. I would think what I am doing is easy and straight forward but not getting that feeling from JSL. I have a more complicated data table but for the purpose of trying to get my code to work I have simplified my table. I have a table with 5 columns, 4 of each have "_Yield" in the heading. 13 rows consist of 1's and 0's and what I am trying to do is create a column for each row that shows the first occurrence of a 1 in the yield columns. I need this to be smart as the column names (other than contain _yield) will not always have the same names or be in the same locations. I have figured out how to just look at the yield columns and have converted this to a matrix where I can then find the values I am looking for. I just cant convert these values into the column headers. The test column shows position in matrix, the result column below shows what I should be getting in the Help column.&amp;nbsp; Thanks in advance.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Shadow_0-1666952766189.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/46687i6B4DC07C27F47AB4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Shadow_0-1666952766189.png" alt="Shadow_0-1666952766189.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;lt;JSL&amp;gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Current Data Table();
lst = dt &amp;lt;&amp;lt; Get Column Names(string);
dt &amp;lt;&amp;lt; clear column selection;

For(i = 1, i &amp;lt;= N Items(lst), i++,
	If(Contains(lst[i], "_Yield") &amp;gt; 0,
		Column(dt, lst[i]) &amp;lt;&amp;lt; set selected;
		selcols = dt &amp;lt;&amp;lt; get selected columns;
	)
);

Mat2 = dt &amp;lt;&amp;lt; Get as Matrix(selcols);
DesList = List();
For(i = 1, i &amp;lt;= N Rows(Mat2), i++,
	Pos = Min(Loc(Mat2[i, 0]));
	Insert Into(DesList, Pos);
);

dt &amp;lt;&amp;lt; New Column("Test", Numeric, Continuous, &amp;lt;&amp;lt;Set Values(DesList));

cols = dt &amp;lt;&amp;lt; Get Column Reference(dt &amp;lt;&amp;lt; Get Column Names);
dt &amp;lt;&amp;lt; New Column("Result",
	formula(
		If(Contains(Eval List(selcols), 1) == 1,
			"B_Yield",
			If(Contains(Eval List(selcols), 1) == 2,
				"C_Yield",
				If(Contains(Eval List(selcols), 1) == 3,
					"D_Yield",
					If(Contains(Eval List(selcols), 1) == 4,
						"E_Yield",
						"PASS"
					)
				)
			)
		)
	)
);

values1 = Column(dt, selcols[1]) &amp;lt;&amp;lt; Get Values;
NewColName = "HELP";
dt &amp;lt;&amp;lt; New Column(NewColName, Character);
newColumn = Column(NewColName);

For(j = 1, j &amp;lt;= N Items(values1), j++, 
//yield = list box(selcols, &amp;lt;&amp;lt; set selected(2,1), Print ("list",yield &amp;lt;&amp;lt; get selected, yield &amp;lt;&amp;lt; get selected indices));
	result = (Deslist[j] &amp;gt;= 1);
	If(
		result &amp;gt;= 1, (newcolumn[j] = selcols),
		Is Missing(result), (newColumn[j] = Parse("PASS"))
	);
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 09 Jun 2023 16:01:12 GMT</pubDate>
    <dc:creator>Shadow</dc:creator>
    <dc:date>2023-06-09T16:01:12Z</dc:date>
    <item>
      <title>How do I get items from a list to output a value from another list ?</title>
      <link>https://community.jmp.com/t5/Discussions/How-do-I-get-items-from-a-list-to-output-a-value-from-another/m-p/561711#M77480</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;New to JMP and have searched and read loads of help and going around in circles. I would think what I am doing is easy and straight forward but not getting that feeling from JSL. I have a more complicated data table but for the purpose of trying to get my code to work I have simplified my table. I have a table with 5 columns, 4 of each have "_Yield" in the heading. 13 rows consist of 1's and 0's and what I am trying to do is create a column for each row that shows the first occurrence of a 1 in the yield columns. I need this to be smart as the column names (other than contain _yield) will not always have the same names or be in the same locations. I have figured out how to just look at the yield columns and have converted this to a matrix where I can then find the values I am looking for. I just cant convert these values into the column headers. The test column shows position in matrix, the result column below shows what I should be getting in the Help column.&amp;nbsp; Thanks in advance.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Shadow_0-1666952766189.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/46687i6B4DC07C27F47AB4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Shadow_0-1666952766189.png" alt="Shadow_0-1666952766189.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;lt;JSL&amp;gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Current Data Table();
lst = dt &amp;lt;&amp;lt; Get Column Names(string);
dt &amp;lt;&amp;lt; clear column selection;

For(i = 1, i &amp;lt;= N Items(lst), i++,
	If(Contains(lst[i], "_Yield") &amp;gt; 0,
		Column(dt, lst[i]) &amp;lt;&amp;lt; set selected;
		selcols = dt &amp;lt;&amp;lt; get selected columns;
	)
);

Mat2 = dt &amp;lt;&amp;lt; Get as Matrix(selcols);
DesList = List();
For(i = 1, i &amp;lt;= N Rows(Mat2), i++,
	Pos = Min(Loc(Mat2[i, 0]));
	Insert Into(DesList, Pos);
);

dt &amp;lt;&amp;lt; New Column("Test", Numeric, Continuous, &amp;lt;&amp;lt;Set Values(DesList));

cols = dt &amp;lt;&amp;lt; Get Column Reference(dt &amp;lt;&amp;lt; Get Column Names);
dt &amp;lt;&amp;lt; New Column("Result",
	formula(
		If(Contains(Eval List(selcols), 1) == 1,
			"B_Yield",
			If(Contains(Eval List(selcols), 1) == 2,
				"C_Yield",
				If(Contains(Eval List(selcols), 1) == 3,
					"D_Yield",
					If(Contains(Eval List(selcols), 1) == 4,
						"E_Yield",
						"PASS"
					)
				)
			)
		)
	)
);

values1 = Column(dt, selcols[1]) &amp;lt;&amp;lt; Get Values;
NewColName = "HELP";
dt &amp;lt;&amp;lt; New Column(NewColName, Character);
newColumn = Column(NewColName);

For(j = 1, j &amp;lt;= N Items(values1), j++, 
//yield = list box(selcols, &amp;lt;&amp;lt; set selected(2,1), Print ("list",yield &amp;lt;&amp;lt; get selected, yield &amp;lt;&amp;lt; get selected indices));
	result = (Deslist[j] &amp;gt;= 1);
	If(
		result &amp;gt;= 1, (newcolumn[j] = selcols),
		Is Missing(result), (newColumn[j] = Parse("PASS"))
	);
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 09 Jun 2023 16:01:12 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-do-I-get-items-from-a-list-to-output-a-value-from-another/m-p/561711#M77480</guid>
      <dc:creator>Shadow</dc:creator>
      <dc:date>2023-06-09T16:01:12Z</dc:date>
    </item>
    <item>
      <title>Re: How do I get items from a list to output a value from another list ?</title>
      <link>https://community.jmp.com/t5/Discussions/How-do-I-get-items-from-a-list-to-output-a-value-from-another/m-p/561727#M77484</link>
      <description>&lt;P&gt;One example:&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 = New Table("Untitled",
	Add Rows(3),
	New Column("Column 1", Numeric, "Continuous", Format("Best", 12), Set Values([0, 0, 1, 0])),
	New Column("A_YIELD", Numeric, "Continuous", Format("Best", 12), Set Values([0, 0, 1, 0])),
	New Column("B_YIELD", Numeric, "Continuous", Format("Best", 12), Set Values([1, 0, 0, 0])),
	New Column("C_YIELD", Numeric, "Continuous", Format("Best", 12), Set Values([1, 1, 1, 0]))
);

// Get column names which end in _YIELD
yield_cols = Filter Each({col_name}, dt &amp;lt;&amp;lt; Get Column Names("Continuous", "String"),
	Ends With(col_name, "_YIELD");
);

// create new column to get _YIELD column name
dt &amp;lt;&amp;lt; New Column("RESULT", Character, Nominal, &amp;lt;&amp;lt; Set Each Value(
	one_idx = Loc(dt[Row(), yield_cols], 1);
	If(N Items(one_idx),
		yield_cols[Min(one_idx)];
	,
		"PASS"
	);
));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jthi_0-1666953606643.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/46689iB0BB4FA3930E683C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jthi_0-1666953606643.png" alt="jthi_0-1666953606643.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Oct 2022 10:40:52 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-do-I-get-items-from-a-list-to-output-a-value-from-another/m-p/561727#M77484</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2022-10-28T10:40:52Z</dc:date>
    </item>
    <item>
      <title>Re: How do I get items from a list to output a value from another list ?</title>
      <link>https://community.jmp.com/t5/Discussions/How-do-I-get-items-from-a-list-to-output-a-value-from-another/m-p/562817#M77586</link>
      <description>&lt;P&gt;Hi jthi,&lt;/P&gt;&lt;P&gt;Thanks for your reply. Filter Each isn't an active function for me. Maybe because I am using V15 but I was able to use my current way of selecting column names with your one_idx&amp;nbsp; equation and it works a treat. I had been struggling with the Loc function last week so this really helps.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Nov 2022 11:21:38 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-do-I-get-items-from-a-list-to-output-a-value-from-another/m-p/562817#M77586</guid>
      <dc:creator>Shadow</dc:creator>
      <dc:date>2022-11-01T11:21:38Z</dc:date>
    </item>
  </channel>
</rss>

