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%3ECome%20posso%20ottenere%20elementi%20da%20un%20elenco%20per%20produrre%20un%20valore%20da%20un%20altro%20elenco%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-561711%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3ECIAO%2C%3C%2FP%3E%0A%3CP%3ENuovo%20in%20JMP%20e%20ho%20cercato%20e%20letto%20un%20sacco%20di%20aiuto%20e%20ho%20girato%20in%20tondo.%20Penso%20che%20quello%20che%20sto%20facendo%20sia%20facile%20e%20diretto%2C%20ma%20non%20ho%20questa%20sensazione%20da%20JSL.%20Ho%20una%20tabella%20di%20dati%20pi%C3%B9%20complicata%20ma%20allo%20scopo%20di%20provare%20a%20far%20funzionare%20il%20mio%20codice%20ho%20semplificato%20la%20mia%20tabella.%20Ho%20una%20tabella%20con%205%20colonne%2C%204%20di%20ciascuna%20hanno%20%22_Yield%22%20nell'intestazione.%2013%20righe%20sono%20costituite%20da%201%20e%200%20e%20quello%20che%20sto%20cercando%20di%20fare%20%C3%A8%20creare%20una%20colonna%20per%20ogni%20riga%20che%20mostri%20la%20prima%20occorrenza%20di%20un%201%20nelle%20colonne%20di%20rendimento.%20Ho%20bisogno%20che%20questo%20sia%20intelligente%20poich%C3%A9%20i%20nomi%20delle%20colonne%20(diversi%20da%20contenere%20_yield)%20non%20avranno%20sempre%20gli%20stessi%20nomi%20o%20si%20troveranno%20nelle%20stesse%20posizioni.%20Ho%20capito%20come%20guardare%20solo%20le%20colonne%20dei%20rendimenti%20e%20l'ho%20convertito%20in%20una%20matrice%20dove%20posso%20quindi%20trovare%20i%20valori%20che%20sto%20cercando.%20Non%20riesco%20proprio%20a%20convertire%20questi%20valori%20nelle%20intestazioni%20di%20colonna.%20La%20colonna%20del%20test%20mostra%20la%20posizione%20nella%20matrice%2C%20la%20colonna%20dei%20risultati%20in%20basso%20mostra%20cosa%20dovrei%20ottenere%20nella%20colonna%20della%20Guida.Grazie%20in%20anticipo.%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%3EPersonalizzazione%20di%20massa%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%3ERi%3A%20Come%20posso%20ottenere%20elementi%20da%20un%20elenco%20per%20produrre%20un%20valore%20da%20un%20altro%20elenco%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-562817%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3Eciao%20jti%2C%3C%2FP%3E%3CP%3EGrazie%20per%20la%20tua%20risposta.%20Filter%20Each%20non%20%C3%A8%20una%20funzione%20attiva%20per%20me.%20Forse%20perch%C3%A9%20sto%20usando%20V15%20ma%20sono%20stato%20in%20grado%20di%20usare%20il%20mio%20modo%20attuale%20di%20selezionare%20i%20nomi%20delle%20colonne%20con%20la%20tua%20equazione%20one_idx%20e%20funziona%20a%20meraviglia.%20Ho%20avuto%20problemi%20con%20la%20funzione%20Loc%20la%20scorsa%20settimana%2C%20quindi%20questo%20aiuta%20davvero.%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%3ERi%3A%20Come%20posso%20ottenere%20elementi%20da%20un%20elenco%20per%20produrre%20un%20valore%20da%20un%20altro%20elenco%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%20esempio%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