cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
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.