cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
Lien
Level II

using List as variable in an if-statement

I am trying to create a list with all column names and turning some of them into a variable.

That variable should be going into an if-statement but I am struggling with the "name unresolved" error. 

I'm guessing that JMP cannot find my previously defined variable but I do not know how to fix it even though I'm sure it should be quite simple.

dt = Current Data Table();
ColumnList = dt << Get Column Names(String);

A = ColumnList[40];

If(Contains(A, "test"),
var = :A[dt << get rows where( :column == value)];);
// I cannot seem to get it to take the column saved in A

I would also like to know how I could potentially use the text of that variable in defining a column name.

dt << New Column( "[A] at 45km/h");

Thanks in advance!

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: using List as variable in an if-statement

You need to use As Column() function, and restructure the name on the new column a bit

dt = 
// Open Data Table: big class.jmp
// → Data Table( "big class" )
Open( "$SAMPLE_DATA/big class.jmp" );

ColumnList = dt << Get Column Names( String );
value = 60;
A = ColumnList[4];

If( Contains( A, "hei" ),
	var = As Column( A )[dt << get rows where( As Column( a ) == value )]
);

dt << New Column( "[" || A || "] at 45km/h");

 

Jim

View solution in original post

1 REPLY 1
txnelson
Super User

Re: using List as variable in an if-statement

You need to use As Column() function, and restructure the name on the new column a bit

dt = 
// Open Data Table: big class.jmp
// → Data Table( "big class" )
Open( "$SAMPLE_DATA/big class.jmp" );

ColumnList = dt << Get Column Names( String );
value = 60;
A = ColumnList[4];

If( Contains( A, "hei" ),
	var = As Column( A )[dt << get rows where( As Column( a ) == value )]
);

dt << New Column( "[" || A || "] at 45km/h");

 

Jim