JSL script to check if a single cell value is in a listGiven a data table with a column of limited values (se examples below), I would like to write a script that looks at the first cell and checks if it is in a list of values. The purpose would be to use whatever that first value as the conditoin for an IF statement that would then point to a certain set of tasks.
Anyone have an idea how to do this?
thanks
e.g.
or
Re: JSL script to check if a single cell value is in a listThanks @pmroz and @txnelson for the scripting help. To be more specific, what I am looking for is to use the check of whether or not the value of the first cell is in the list as the conditions for an if statement which will drive some other actions. I think that both of your scripts fill another array but they're not a strict T/F. I will try to use them and let you know what happens.
Re: JSL script to check if a single cell value is in a listThis might be helpful:
dt = New Table( "test", Add Rows( 5 ),
New Column( "CAT", Character, "Nominal",
Set Values( {"A", "B", "C", "D", "E"} ) ),
New Column( "time", Numeric, "Continuous", Format( "Best", 12 ),
Set Values( [1, 2, 3, 4, 5] ) )
);
look_for_list = {"B", "D"};
found_rows = dt << get rows where(contains(look_for_list, as column(dt, "CAT")));
print(found_rows);
[2, 4]
Re: JSL script to check if a single cell value is in a listI am not sure exactly what you are asking for, however, below is a script that might point you in the right direction
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/big class.jmp" );
theList = {59, 66};
For( i = 1, i <= N Rows( dt ), i++,
If( N Rows( Loc( theList, :height[i] ) ) > 0,
Show( i )
)
);Re: JSL script to check if a single cell value is in a listCame across this thread looking for something similar for closing lingering open data tables while testing code. Used your simple code above. Thought I'd post in case it's useful for anyone coming across this thread:
// list of table names that I want to make sure are closed before running the script
tname = { "TABLE1", "TABLE2", "TABLE3", "TABLE4" };
// loop to see if open tables match the name in the list above, then close them
// need to restart the i counter to i = 0 because it seems closing a table changes the 'i' number associated with the table
For( i = 1, i <= N Table(), i++,
If( N Rows (Loc( tname, Data Table(i) << Get Name ) ) > 0,
Close(Data Table(i), no save);
i = 0;
)
);