cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • JMP will suspend normal business operations for our Winter Holiday beginning on Wednesday, Dec. 24, 2025, at 5:00 p.m. ET (2:00 p.m. ET for JMP Accounts Receivable).
    Regular business hours will resume at 9:00 a.m. EST on Friday, Jan. 2, 2026.
  • We’re retiring the File Exchange at the end of this year. The JMP Marketplace is now your destination for add-ins and extensions.

Discussions

Solve problems, and share tips and tricks with other JMP users.
%3CLINGO-SUB%20id%3D%22lingo-sub-561711%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%E5%A6%82%E4%BD%95%E5%BE%9E%E5%88%97%E8%A1%A8%E4%B8%AD%E7%8D%B2%E5%8F%96%E9%A0%85%E7%9B%AE%E4%BB%A5%E8%BC%B8%E5%87%BA%E5%8F%A6%E4%B8%80%E5%80%8B%E5%88%97%E8%A1%A8%E4%B8%AD%E7%9A%84%E5%80%BC%EF%BC%9F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-561711%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%E4%BD%A0%E5%A5%BD%EF%BC%8C%3C%2FP%3E%0A%3CP%3EJMP%20%E6%96%B0%E6%89%8B%EF%BC%8C%E5%B7%B2%E7%B6%93%E6%90%9C%E7%B4%A2%E4%B8%A6%E9%96%B1%E8%AE%80%E4%BA%86%E5%A4%A7%E9%87%8F%E5%B9%AB%E5%8A%A9%E4%B8%A6%E5%85%9C%E5%9C%88%E5%AD%90%E3%80%82%20%E6%88%91%E8%AA%8D%E7%82%BA%E6%88%91%E6%89%80%E5%81%9A%E7%9A%84%E4%BA%8B%E6%83%85%E6%98%AF%E7%B0%A1%E5%96%AE%E7%9B%B4%E6%8E%A5%E7%9A%84%EF%BC%8C%E4%BD%86%20JSL%20%E5%8D%BB%E6%B2%92%E6%9C%89%E9%80%99%E7%A8%AE%E6%84%9F%E8%A6%BA%E3%80%82%20%E6%88%91%E6%9C%89%E4%B8%80%E5%80%8B%E6%9B%B4%E8%A4%87%E9%9B%9C%E7%9A%84%E6%95%B8%E6%93%9A%E8%A1%A8%EF%BC%8C%E4%BD%86%E7%82%BA%E4%BA%86%E8%AE%93%E6%88%91%E7%9A%84%E4%BB%A3%E7%A2%BC%E6%AD%A3%E5%B8%B8%E5%B7%A5%E4%BD%9C%EF%BC%8C%E6%88%91%E7%B0%A1%E5%8C%96%E4%BA%86%E6%88%91%E7%9A%84%E8%A1%A8%E3%80%82%20%E6%88%91%E6%9C%89%E4%B8%80%E5%80%8B%E5%8C%85%E5%90%AB%205%20%E5%88%97%E7%9A%84%E8%A1%A8%E6%A0%BC%EF%BC%8C%E5%85%B6%E4%B8%AD%204%20%E5%88%97%E7%9A%84%E6%A8%99%E9%A1%8C%E4%B8%AD%E5%8C%85%E5%90%AB%E2%80%9C_Yield%E2%80%9D%E3%80%82%2013%20%E8%A1%8C%E7%94%B1%201%20%E5%92%8C%200%20%E7%B5%84%E6%88%90%EF%BC%8C%E6%88%91%E6%83%B3%E8%A6%81%E5%81%9A%E7%9A%84%E6%98%AF%E7%82%BA%E6%AF%8F%E4%B8%80%E8%A1%8C%E5%89%B5%E5%BB%BA%E4%B8%80%E5%80%8B%E5%88%97%EF%BC%8C%E9%A1%AF%E7%A4%BA%E7%94%A2%E9%87%8F%E5%88%97%E4%B8%AD%E7%AC%AC%E4%B8%80%E6%AC%A1%E5%87%BA%E7%8F%BE%E7%9A%84%201%E3%80%82%20%E6%88%91%E9%9C%80%E8%A6%81%E5%AE%83%E6%98%AF%E6%99%BA%E8%83%BD%E7%9A%84%EF%BC%8C%E5%9B%A0%E7%82%BA%E5%88%97%E5%90%8D%E7%A8%B1%EF%BC%88%E5%8C%85%E5%90%AB%20_yield%20%E9%99%A4%E5%A4%96%EF%BC%89%E4%B8%A6%E4%B8%8D%E7%B8%BD%E6%98%AF%E5%85%B7%E6%9C%89%E7%9B%B8%E5%90%8C%E7%9A%84%E5%90%8D%E7%A8%B1%E6%88%96%E4%BD%8D%E6%96%BC%E7%9B%B8%E5%90%8C%E7%9A%84%E4%BD%8D%E7%BD%AE%E3%80%82%20%E6%88%91%E5%B7%B2%E7%B6%93%E5%BC%84%E6%B8%85%E6%A5%9A%E5%A6%82%E4%BD%95%E6%9F%A5%E7%9C%8B%E7%94%A2%E9%87%8F%E5%88%97%E4%B8%A6%E5%B0%87%E5%85%B6%E8%BD%89%E6%8F%9B%E7%82%BA%E7%9F%A9%E9%99%A3%EF%BC%8C%E7%84%B6%E5%BE%8C%E6%88%91%E5%8F%AF%E4%BB%A5%E5%9C%A8%E5%85%B6%E4%B8%AD%E6%89%BE%E5%88%B0%E6%88%91%E6%AD%A3%E5%9C%A8%E5%B0%8B%E6%89%BE%E7%9A%84%E5%80%BC%E3%80%82%20%E6%88%91%E5%8F%AA%E6%98%AF%E7%84%A1%E6%B3%95%E5%B0%87%E9%80%99%E4%BA%9B%E5%80%BC%E8%BD%89%E6%8F%9B%E7%82%BA%E5%88%97%E6%A8%99%E9%A1%8C%E3%80%82%20%E6%B8%AC%E8%A9%A6%E5%88%97%E9%A1%AF%E7%A4%BA%E7%9F%A9%E9%99%A3%E4%B8%AD%E7%9A%84%E4%BD%8D%E7%BD%AE%EF%BC%8C%E4%B8%8B%E9%9D%A2%E7%9A%84%E7%B5%90%E6%9E%9C%E5%88%97%E9%A1%AF%E7%A4%BA%E6%88%91%E6%87%89%E8%A9%B2%E5%9C%A8%E5%B9%AB%E5%8A%A9%E5%88%97%E4%B8%AD%E7%8D%B2%E5%BE%97%E7%9A%84%E5%85%A7%E5%AE%B9%E3%80%82%E6%8F%90%E5%89%8D%E8%87%B4%E8%AC%9D%E3%80%82%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Shadow_0-1666952766189.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22Shadow_0-1666952766189.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22Shadow_0-1666952766189.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F46687i6B4DC07C27F47AB4%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Shadow_0-1666952766189.png%22%20alt%3D%22Shadow_0-1666952766189.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CJSL%3E%3C%2FJSL%3E%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3Edt%20%3D%20Current%20Data%20Table()%3B%0Alst%20%3D%20dt%20%26lt%3B%26lt%3B%20Get%20Column%20Names(string)%3B%0Adt%20%26lt%3B%26lt%3B%20clear%20column%20selection%3B%0A%0AFor(i%20%3D%201%2C%20i%20%26lt%3B%3D%20N%20Items(lst)%2C%20i%2B%2B%2C%0A%20If(Contains(lst%5Bi%5D%2C%20%22_Yield%22)%20%26gt%3B%200%2C%0A%20%20Column(dt%2C%20lst%5Bi%5D)%20%26lt%3B%26lt%3B%20set%20selected%3B%0A%20%20selcols%20%3D%20dt%20%26lt%3B%26lt%3B%20get%20selected%20columns%3B%0A%20)%0A)%3B%0A%0AMat2%20%3D%20dt%20%26lt%3B%26lt%3B%20Get%20as%20Matrix(selcols)%3B%0ADesList%20%3D%20List()%3B%0AFor(i%20%3D%201%2C%20i%20%26lt%3B%3D%20N%20Rows(Mat2)%2C%20i%2B%2B%2C%0A%20Pos%20%3D%20Min(Loc(Mat2%5Bi%2C%200%5D))%3B%0A%20Insert%20Into(DesList%2C%20Pos)%3B%0A)%3B%0A%0Adt%20%26lt%3B%26lt%3B%20New%20Column(%22Test%22%2C%20Numeric%2C%20Continuous%2C%20%26lt%3B%3CSET%20values%3D%22%22%3E%3D%201)%3B%0A%20If(%0A%20%20result%20%26gt%3B%3D%201%2C%20(newcolumn%5Bj%5D%20%3D%20selcols)%2C%0A%20%20Is%20Missing(result)%2C%20(newColumn%5Bj%5D%20%3D%20Parse(%22PASS%22))%0A%20)%3B%0A)%3B%3C%2FSET%3E%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-561711%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CLINGO-LABEL%3E%E5%A4%A7%E8%A6%8F%E6%A8%A1%E5%AE%9A%E5%88%B6%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-562817%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%E5%9B%9E%E5%A4%8D%EF%BC%9A%E5%A6%82%E4%BD%95%E5%BE%9E%E5%88%97%E8%A1%A8%E4%B8%AD%E7%8D%B2%E5%8F%96%E9%A0%85%E7%9B%AE%E4%BB%A5%E8%BC%B8%E5%87%BA%E5%8F%A6%E4%B8%80%E5%80%8B%E5%88%97%E8%A1%A8%E4%B8%AD%E7%9A%84%E5%80%BC%EF%BC%9F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-562817%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%E5%97%A8%EF%BC%8Cjthi%EF%BC%8C%3C%2FP%3E%3CP%3E%E6%84%9F%E8%AC%9D%E6%82%A8%E7%9A%84%E5%9B%9E%E5%A4%8D%E3%80%82%20Filter%20Each%20%E5%B0%8D%E6%88%91%E4%BE%86%E8%AA%AA%E4%B8%8D%E6%98%AF%E4%B8%80%E5%80%8B%E6%B4%BB%E8%BA%8D%E7%9A%84%E5%8A%9F%E8%83%BD%E3%80%82%20%E4%B9%9F%E8%A8%B1%E6%98%AF%E5%9B%A0%E7%82%BA%E6%88%91%E4%BD%BF%E7%94%A8%E7%9A%84%E6%98%AF%20V15%EF%BC%8C%E4%BD%86%E6%88%91%E8%83%BD%E5%A4%A0%E4%BD%BF%E7%94%A8%E7%95%B6%E5%89%8D%E7%9A%84%E6%96%B9%E5%BC%8F%E9%80%9A%E9%81%8E%E6%82%A8%E7%9A%84%20one_idx%20%E6%96%B9%E7%A8%8B%E9%81%B8%E6%93%87%E5%88%97%E5%90%8D%E7%A8%B1%EF%BC%8C%E4%B8%A6%E4%B8%94%E5%AE%83%E5%BE%88%E6%9C%89%E6%95%88%E3%80%82%20%E4%B8%8A%E9%80%B1%E6%88%91%E4%B8%80%E7%9B%B4%E5%9C%A8%E5%8A%AA%E5%8A%9B%E4%BD%BF%E7%94%A8%20Loc%20%E5%87%BD%E6%95%B8%EF%BC%8C%E6%89%80%E4%BB%A5%E9%80%99%E7%A2%BA%E5%AF%A6%E5%BE%88%E6%9C%89%E5%B9%AB%E5%8A%A9%E3%80%82%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-561727%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%E5%9B%9E%E5%A4%8D%EF%BC%9A%E5%A6%82%E4%BD%95%E5%BE%9E%E5%88%97%E8%A1%A8%E4%B8%AD%E7%8D%B2%E5%8F%96%E9%A0%85%E7%9B%AE%E4%BB%A5%E8%BC%B8%E5%87%BA%E5%8F%A6%E4%B8%80%E5%80%8B%E5%88%97%E8%A1%A8%E4%B8%AD%E7%9A%84%E5%80%BC%EF%BC%9F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-561727%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%E4%B8%80%E5%80%8B%E4%BE%8B%E5%AD%90%EF%BC%9A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3ENames%20Default%20To%20Here(1)%3B%0A%0Adt%20%3D%20New%20Table(%22Untitled%22%2C%0A%20Add%20Rows(3)%2C%0A%20New%20Column(%22Column%201%22%2C%20Numeric%2C%20%22Continuous%22%2C%20Format(%22Best%22%2C%2012)%2C%20Set%20Values(%5B0%2C%200%2C%201%2C%200%5D))%2C%0A%20New%20Column(%22A_YIELD%22%2C%20Numeric%2C%20%22Continuous%22%2C%20Format(%22Best%22%2C%2012)%2C%20Set%20Values(%5B0%2C%200%2C%201%2C%200%5D))%2C%0A%20New%20Column(%22B_YIELD%22%2C%20Numeric%2C%20%22Continuous%22%2C%20Format(%22Best%22%2C%2012)%2C%20Set%20Values(%5B1%2C%200%2C%200%2C%200%5D))%2C%0A%20New%20Column(%22C_YIELD%22%2C%20Numeric%2C%20%22Continuous%22%2C%20Format(%22Best%22%2C%2012)%2C%20Set%20Values(%5B1%2C%201%2C%201%2C%200%5D))%0A)%3B%0A%0A%2F%2F%20Get%20column%20names%20which%20end%20in%20_YIELD%0Ayield_cols%20%3D%20Filter%20Each(%7Bcol_name%7D%2C%20dt%20%26lt%3B%26lt%3B%20Get%20Column%20Names(%22Continuous%22%2C%20%22String%22)%2C%0A%20Ends%20With(col_name%2C%20%22_YIELD%22)%3B%0A)%3B%0A%0A%2F%2F%20create%20new%20column%20to%20get%20_YIELD%20column%20name%0Adt%20%26lt%3B%26lt%3B%20New%20Column(%22RESULT%22%2C%20Character%2C%20Nominal%2C%20%26lt%3B%26lt%3B%20Set%20Each%20Value(%0A%20one_idx%20%3D%20Loc(dt%5BRow()%2C%20yield_cols%5D%2C%201)%3B%0A%20If(N%20Items(one_idx)%2C%0A%20%20yield_cols%5BMin(one_idx)%5D%3B%0A%20%2C%0A%20%20%22PASS%22%0A%20)%3B%0A))%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22jthi_0-1666953606643.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22jthi_0-1666953606643.png%22%20style%3D%22width%3A%20319px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22jthi_0-1666953606643.png%22%20style%3D%22width%3A%20319px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F46689iB0BB4FA3930E683C%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22jthi_0-1666953606643.png%22%20alt%3D%22jthi_0-1666953606643.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Choose Language Hide Translation Bar
Shadow
Level I

How do I get items from a list to output a value from another list ?

Hi,

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.  Thanks in advance. 

Shadow_0-1666952766189.png

<JSL>

dt = Current Data Table();
lst = dt << Get Column Names(string);
dt << clear column selection;

For(i = 1, i <= N Items(lst), i++,
	If(Contains(lst[i], "_Yield") > 0,
		Column(dt, lst[i]) << set selected;
		selcols = dt << get selected columns;
	)
);

Mat2 = dt << Get as Matrix(selcols);
DesList = List();
For(i = 1, i <= N Rows(Mat2), i++,
	Pos = Min(Loc(Mat2[i, 0]));
	Insert Into(DesList, Pos);
);

dt << New Column("Test", Numeric, Continuous, <<Set Values(DesList));

cols = dt << Get Column Reference(dt << Get Column Names);
dt << 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]) << Get Values;
NewColName = "HELP";
dt << New Column(NewColName, Character);
newColumn = Column(NewColName);

For(j = 1, j <= N Items(values1), j++, 
//yield = list box(selcols, << set selected(2,1), Print ("list",yield << get selected, yield << get selected indices));
	result = (Deslist[j] >= 1);
	If(
		result >= 1, (newcolumn[j] = selcols),
		Is Missing(result), (newColumn[j] = Parse("PASS"))
	);
);
1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: How do I get items from a list to output a value from another list ?

One example:

 

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 << Get Column Names("Continuous", "String"),
	Ends With(col_name, "_YIELD");
);

// create new column to get _YIELD column name
dt << New Column("RESULT", Character, Nominal, << Set Each Value(
	one_idx = Loc(dt[Row(), yield_cols], 1);
	If(N Items(one_idx),
		yield_cols[Min(one_idx)];
	,
		"PASS"
	);
));

jthi_0-1666953606643.png

 

-Jarmo

View solution in original post

2 REPLIES 2
jthi
Super User

Re: How do I get items from a list to output a value from another list ?

One example:

 

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 << Get Column Names("Continuous", "String"),
	Ends With(col_name, "_YIELD");
);

// create new column to get _YIELD column name
dt << New Column("RESULT", Character, Nominal, << Set Each Value(
	one_idx = Loc(dt[Row(), yield_cols], 1);
	If(N Items(one_idx),
		yield_cols[Min(one_idx)];
	,
		"PASS"
	);
));

jthi_0-1666953606643.png

 

-Jarmo
Shadow
Level I

Re: How do I get items from a list to output a value from another list ?

Hi jthi,

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  equation and it works a treat. I had been struggling with the Loc function last week so this really helps. 

 

Recommended Articles