Our World Statistics Day conversations have been a great reminder of how much statistics can inform our lives. Do you have an example of how statistics has made a difference in your life? Share your story with the Community!
Choose Language Hide Translation Bar
Highlighted
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
Highlighted
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
Highlighted
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;
Article Labels