Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- JMP User Community
- :
- Discussions
- :
- Scripting to skip changing a column if the column ...

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Jan 5, 2017 8:30 AM
(814 views)

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Jan 5, 2017 8:45 AM
(1601 views)

Solution

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

4 REPLIES

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Jan 5, 2017 8:45 AM
(1602 views)

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Jan 6, 2017 12:53 AM
(795 views)

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Jan 6, 2017 5:25 AM
(777 views)

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Jan 6, 2017 1:59 AM
(789 views)

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