turn on suggestions

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

Showing results for

- JMP User Community
- :
- Discussions
- :
- Discussions
- :
- combining 'set each value' and 'if'

Topic Options

- 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

Feb 29, 2012 10:14 AM
(2957 views)

Hello,

I have a problem using 'if' in the evaluation of 'set each value'. In the data table (dt_optics) are numeric continuous columns containing counts of a control. Now, I need to check for nonzero counts and store the result in new columns (to later perform logistic regression). The code I am using is:

column_list = dt_optics << get column names;

n_columns = N Col**(** dt_optics **)**;

For**(** i = **3**, i <= n_columns, i++,

column_name = Char**(** Column Name**(** i **)** **)** || "_bin";

dt_optics << New Column**(** column_name,

continuous,

ordinal,

set each value**(** If**(** **(**Column**(** dt_optics, column_list**[**i**]** **))** == **0**, **0**, **1** **)** **)**

**)**;

**)**;

In the column I create all values are 1, no matter what the value in the initial column was (I am sure that there are nonzeros in the initial column). Can somebody help me with that?

Thanks a lot,

Arno

1 ACCEPTED SOLUTION

Accepted Solutions

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

You need to append square brackets to the column within SetEachValue() to involve the column values rather than the column object.

This should work (only change is the [ ])

For**(** i = **3**, i <= n_columns, i++,

column_name = Char**(** Column Name**(** i **)** **)** || "_bin";

dt_optics << New Column**(** column_name,

continuous,

ordinal,

set each value**(** If**(** Column**(** dt_optics, column_list**[**i**]** **)[]** == **0**, **0**, **1** **)** **)**

**)**;

**)**;

1 REPLY

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

You need to append square brackets to the column within SetEachValue() to involve the column values rather than the column object.

This should work (only change is the [ ])

For**(** i = **3**, i <= n_columns, i++,

column_name = Char**(** Column Name**(** i **)** **)** || "_bin";

dt_optics << New Column**(** column_name,

continuous,

ordinal,

set each value**(** If**(** Column**(** dt_optics, column_list**[**i**]** **)[]** == **0**, **0**, **1** **)** **)**

**)**;

**)**;