cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Choose Language Hide Translation Bar
qspringleaf
Level III

script for auto column filling

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