cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
The Discovery Summit 2025 Call for Content is open! Submit an abstract today to present at our premier analytics conference.
Get the free JMP Student Edition for qualified students and instructors at degree granting institutions.
Choose Language Hide Translation Bar
View Original Published Thread

script for auto column filling

qspringleaf
Level III

one question about script for column filling. now have one table for a lot kinds of fruit on sale, and a list includes fruit name that sold out already.

how to new create one column (name "sold out?"), and then judge by checking whether the fruit name match with the "sold out fruit list" (apple/durain/…sold out already), if yes, fill in "Y", if no, fill in "N", thanks a lot.

 

Fruit Namesold out?
AppleY
BananaN
durainY
pearN
orangeN
2 REPLIES 2
txnelson
Super User


Re: script for auto column filling

Here is a solution using a JMP List as the input for the sold out fruit.  I also convert the new column to static values by deleting the formula at the end, since if you save the data table, and then reopen it, the column will fail if a JMP list by the name of soldList is not present

Names Default To Here( 1 );
dt = New Table( "Fruit",
	New Column( "Fruit Name",
		character,
		values( {"Apple", "Banana", "Durain", "Pear", "Orange"} )
	)
);

soldList = {"Apple", "Durain"};

dt << New Column( "Sold Out",
	character,
	formula( If( N Rows( Loc( soldList, :Fruit Name ) ), "Y", "N" ) )
);
dt:Sold Out << delete formula;
Jim
ThuongLe
Level IV


Re: script for auto column filling

or you can use Contains keyword to check. I'm using same example code from JIM

Names Default To Here( 1 );
dt = New Table( "Fruit",
	New Column( "Fruit Name",
		character,
		values( {"Apple", "Banana", "Durain", "Pear", "Orange"} )
	)
);

soldList = {"Apple", "Durain"};

dt << New Column( "Sold Out",
	character,
	formula( If( contains(soldList, :Fruit Name), "Y", "N" ) )
);
dt:Fruit Name << delete formula;
Thuong Le