Share your ideas for the JMP Scripting Unsession at Discovery Summit by September 17th. We hope to see you there!
Choose Language Hide Translation Bar
Highlighted

JSL script to check if a single cell value is in a list

Given 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.

CATtime
A1
B2
C3
D4
E5

or

CATtime
V1
W2
X3
Y4
Z5
3 REPLIES 3
Highlighted
txnelson
Super User

Re: JSL script to check if a single cell value is in a list

I 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 )
	)
);
Jim
Highlighted
pmroz
Super User

Re: JSL script to check if a single cell value is in a list

This 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]
Highlighted

Re: JSL script to check if a single cell value is in a list

Thanks @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.

Article Labels

    There are no labels assigned to this post.