cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
Joe
Joe
Level I

Scripting to skip changing a column if the column is not present

Hi All,

 

Is there a way in which a piece of script can automatically be ignored if the targeted column is not present? For example I have the scripting shown below, and sometimes there is not a "Numerical C" available (It is a piece of automation which may or may not have 3 variables). The script currently stalls on this piece when there is no "Numerical C" to be found; ideally I will be wanting to make a script with multiple "Numerical #" which will automatically ignore that piece of the script if it is not present: 

 

Data Table( "Jan 5 Subset" );

Column ("Column") <<Data Type (Numeric);

Column ("Column") <<Modeling Type (Continuous);

Column ("Data") <<Data Type (Numeric);

Column ("Data") <<Modeling Type (Continuous);

Column ("Numerical A") <<Data Type (Numeric);

Column ("Numerical A") <<Modeling Type (Continuous);

Column ("Numerical B") <<Data Type (Numeric);

Column ("Numerical B") <<Modeling Type (Continuous);

Column ("Numerical C") <<Data Type (Numeric);

Column ("Numerical C") <<Modeling Type (Continuous);

 

Thanks you,

Joe

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Scripting to skip changing a column if the column is not present

There are a couple of ways that I do this......

The first is to place the statements that need to be qualified, in an IF function.  The most formal of this would be to get the column names from the data table, and then base the IF condition on if the column was found

dt = Data Table( "Jan 5 Subset" );
If( Contains( dt << get column names( string ), "Column" ),
	Column( "Column" ) << Data Type( Numeric ) << Modeling Type( Continuous )
);

The second method is to let JMP egnore any errors it finds by using a Try function

Try( Column( "Column" ) << Data Type( Numeric ) << Modeling Type( Continuous ) );

The statement may fail, but JMP will continue execution

Jim

View solution in original post

4 REPLIES 4
txnelson
Super User

Re: Scripting to skip changing a column if the column is not present

There are a couple of ways that I do this......

The first is to place the statements that need to be qualified, in an IF function.  The most formal of this would be to get the column names from the data table, and then base the IF condition on if the column was found

dt = Data Table( "Jan 5 Subset" );
If( Contains( dt << get column names( string ), "Column" ),
	Column( "Column" ) << Data Type( Numeric ) << Modeling Type( Continuous )
);

The second method is to let JMP egnore any errors it finds by using a Try function

Try( Column( "Column" ) << Data Type( Numeric ) << Modeling Type( Continuous ) );

The statement may fail, but JMP will continue execution

Jim
Joe
Joe
Level I

Re: Scripting to skip changing a column if the column is not present

Hi Jim,

Thanks for the fast reply. I have tried the top function:

 

dt = Data Table( "Jan 5 Subset" );
If( Contains( dt << get column names( string ), "Column" ),
Column( "Column" ) << Data Type( Numeric ) << Modeling Type( Continuous )
);

 

However I am not sure what to put where "(string)" is in the script?

At the moment the script appears to be failing on this line with "Send Expects Scriptable Object". My current scripting for this would be:

 

IF( Contains(dt << Get column names(string), "Numerical A"),

"Numerical A") <<Data Type (Numeric) <<Modeling Type (Continuous);

 

Apologies if there is something really obvious that I am missing here, thanks in advance.

txnelson
Super User

Re: Scripting to skip changing a column if the column is not present

Here is a script that takes what you said that you had tried, and corrects it so that it should work.  I have also annotated the script to help understand what each statement is doing

// Set a variable "dt" to point to the data table you want to work on
// In the example you showed, it was a table called "Jan 5 Subset"
dt = Data Table("Jan 5 Subset");

// Now request to get from the data table, now referenced by the 
// variable "dt" and return the list as strings
// Using the Contains function, we will check to see if a column
// named "Numerical A" is found in the returned list of column 
// names.  If it is, the comparison will be true and the statements
// following the "," will be executed
IF( Contains(dt << Get column names(string), "Numerical A"),
	// Set the Data Type and Modeling Type for the column "Numerical A"
	Column("Numerical A") <<Data Type (Numeric) <<Modeling Type (Continuous);
// close the IF function
);
Jim
Joe
Joe
Level I

Re: Scripting to skip changing a column if the column is not present

That second piece of scripting works perfectly, thank you very much!