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%3EWie%20erhalte%20ich%20Elemente%20aus%20einer%20Liste%2C%20um%20einen%20Wert%20aus%20einer%20anderen%20Liste%20auszugeben%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-561711%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EHallo%2C%3C%2FP%3E%0A%3CP%3EIch%20bin%20neu%20bei%20JMP%20und%20habe%20jede%20Menge%20Hilfe%20gesucht%20und%20gelesen%20und%20mich%20im%20Kreis%20gedreht.%20Ich%20denke%2C%20dass%20das%2C%20was%20ich%20mache%2C%20einfach%20und%20geradlinig%20ist%2C%20aber%20JSL%20vermittelt%20mir%20dieses%20Gef%C3%BChl%20nicht.%20Ich%20habe%20eine%20kompliziertere%20Datentabelle%2C%20aber%20um%20meinen%20Code%20zum%20Laufen%20zu%20bringen%2C%20habe%20ich%20meine%20Tabelle%20vereinfacht.%20Ich%20habe%20eine%20Tabelle%20mit%205%20Spalten%2C%204%20davon%20haben%20%E2%80%9E_Yield%E2%80%9C%20in%20der%20%C3%9Cberschrift.%2013%20Zeilen%20bestehen%20aus%20Einsen%20und%20Nullen%20und%20ich%20versuche%2C%20f%C3%BCr%20jede%20Zeile%20eine%20Spalte%20zu%20erstellen%2C%20die%20das%20erste%20Vorkommen%20einer%201%20in%20den%20Ertragsspalten%20anzeigt.%20Dies%20muss%20sinnvoll%20sein%2C%20da%20die%20Spaltennamen%20(au%C3%9Fer%20%E2%80%9Econtain%20_yield%E2%80%9C)%20nicht%20immer%20dieselben%20Namen%20haben%20oder%20sich%20an%20denselben%20Stellen%20befinden.%20Ich%20habe%20herausgefunden%2C%20wie%20ich%20mir%20einfach%20die%20Ertragsspalten%20ansehen%20und%20diese%20in%20eine%20Matrix%20umwandeln%20kann%2C%20in%20der%20ich%20dann%20die%20gesuchten%20Werte%20finden%20kann.%20Ich%20kann%20diese%20Werte%20einfach%20nicht%20in%20die%20Spalten%C3%BCberschriften%20umwandeln.%20Die%20Testspalte%20zeigt%20die%20Position%20in%20der%20Matrix%2C%20die%20Ergebnisspalte%20unten%20zeigt%2C%20was%20ich%20in%20der%20Hilfespalte%20erhalten%20sollte.Vielen%20Dank%20im%20Voraus.%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%3EMassenanpassung%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%3EBetreff%3A%20Wie%20bekomme%20ich%20Elemente%20aus%20einer%20Liste%2C%20um%20einen%20Wert%20aus%20einer%20anderen%20Liste%20auszugeben%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-562817%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EHallo%20jthi%2C%3C%2FP%3E%3CP%3EDanke%20f%C3%BCr%20deine%20Antwort.%20Filter%20Each%20ist%20f%C3%BCr%20mich%20keine%20aktive%20Funktion.%20Vielleicht%2C%20weil%20ich%20V15%20verwende%2C%20aber%20ich%20konnte%20meine%20aktuelle%20Methode%20zur%20Auswahl%20von%20Spaltennamen%20mit%20Ihrer%20one_idx-Gleichung%20verwenden%20und%20es%20funktioniert%20hervorragend.%20Ich%20hatte%20letzte%20Woche%20Probleme%20mit%20der%20Loc-Funktion%2C%20das%20hilft%20also%20wirklich.%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%3EBetreff%3A%20Wie%20bekomme%20ich%20Elemente%20aus%20einer%20Liste%2C%20um%20einen%20Wert%20aus%20einer%20anderen%20Liste%20auszugeben%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-561727%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EEin%20Beispiel%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