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%C2%BFC%C3%B3mo%20obtengo%20elementos%20de%20una%20lista%20para%20generar%20un%20valor%20de%20otra%20lista%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-561711%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EHola%2C%3C%2FP%3E%0A%3CP%3ENuevo%20en%20JMP%20y%20he%20buscado%20y%20le%C3%ADdo%20mucha%20ayuda%20y%20dando%20vueltas%20en%20c%C3%ADrculos.%20Creo%20que%20lo%20que%20estoy%20haciendo%20es%20f%C3%A1cil%20y%20directo%2C%20pero%20no%20obtengo%20esa%20sensaci%C3%B3n%20de%20JSL.%20Tengo%20una%20tabla%20de%20datos%20m%C3%A1s%20complicada%2C%20pero%20con%20el%20prop%C3%B3sito%20de%20intentar%20que%20mi%20c%C3%B3digo%20funcione%2C%20he%20simplificado%20mi%20tabla.%20Tengo%20una%20tabla%20con%205%20columnas%2C%204%20de%20cada%20una%20tienen%20%22_Rendimiento%22%20en%20el%20encabezado.%2013%20filas%20constan%20de%201%20y%200%20y%20lo%20que%20intento%20hacer%20es%20crear%20una%20columna%20para%20cada%20fila%20que%20muestre%20la%20primera%20aparici%C3%B3n%20de%20un%201%20en%20las%20columnas%20de%20rendimiento.%20Necesito%20que%20esto%20sea%20inteligente%20ya%20que%20los%20nombres%20de%20las%20columnas%20(aparte%20de%20contener%20_rendimiento)%20no%20siempre%20tendr%C3%A1n%20los%20mismos%20nombres%20ni%20estar%C3%A1n%20en%20las%20mismas%20ubicaciones.%20Descubr%C3%AD%20c%C3%B3mo%20simplemente%20mirar%20las%20columnas%20de%20rendimiento%20y%20convertir%20esto%20en%20una%20matriz%20donde%20luego%20puedo%20encontrar%20los%20valores%20que%20estoy%20buscando.%20Simplemente%20no%20puedo%20convertir%20estos%20valores%20en%20los%20encabezados%20de%20columna.%20La%20columna%20de%20prueba%20muestra%20la%20posici%C3%B3n%20en%20la%20matriz%2C%20la%20columna%20de%20resultados%20a%20continuaci%C3%B3n%20muestra%20lo%20que%20deber%C3%ADa%20obtener%20en%20la%20columna%20de%20Ayuda.Gracias%20de%20antemano.%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%3ELa%20personalizaci%C3%B3n%20en%20masa%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%3ERe%3A%20%C2%BFC%C3%B3mo%20obtengo%20elementos%20de%20una%20lista%20para%20generar%20un%20valor%20de%20otra%20lista%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-562817%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EHola%20Jthi%2C%3C%2FP%3E%3CP%3EGracias%20por%20su%20respuesta.%20Filter%20Each%20no%20es%20una%20funci%C3%B3n%20activa%20para%20m%C3%AD.%20Tal%20vez%20porque%20estoy%20usando%20V15%20pero%20pude%20usar%20mi%20forma%20actual%20de%20seleccionar%20nombres%20de%20columnas%20con%20su%20ecuaci%C3%B3n%20one_idx%20y%20funciona%20de%20maravilla.%20Tuve%20problemas%20con%20la%20funci%C3%B3n%20Loc%20la%20semana%20pasada%2C%20as%C3%AD%20que%20esto%20realmente%20ayuda.%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%3ERe%3A%20%C2%BFC%C3%B3mo%20obtengo%20elementos%20de%20una%20lista%20para%20generar%20un%20valor%20de%20otra%20lista%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-561727%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EUn%20ejemplo%3A%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