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
- :
- Re: Help with column variables

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
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Feb 23, 2018 10:02 AM
(1964 views)

Hi all,

I am having trouble understanding why the following code fails:

```
// This code doesn't work
dt = Current Data Table();
selectedCol = dt << Get Selected Columns();
If( Col Mean( selectedCol[1] ) < Col Mean( selectedCol[2] ),
begin = selectedCol[1];
end = selectedCol[2];
,
begin = selectedCol[2];
end = selectedCol[1];
);
```

I want the whole column reassigned to the begin/end variables, but it doesn't happen. I tried this:

```
// This code still doesn't work
dt = Current Data Table();
selectedCol = dt << Get Selected Columns();
If( Col Mean( As Column( selectedCol[1] ) ) < Col Mean( As Column( selectedCol[2] ) ),
begin = As Column( selectedCol[1] );
end = As Column( selectedCol[2] );
,
begin = As Column( selectedCol[2] );
end = As Column( selectedCol[1] );
);
```

Can I get some help, conceptual and practical both. This seems really simple, but I'm obviously missing something important.

John

1 ACCEPTED SOLUTION

Accepted Solutions

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

Hi @john_madden,

Two things I notice here. First, JSL evaluates nested functions from the outside in, meaning you need an Eval() for the reference to the column that is part of your list. Second, if I'm understanding you correctly, you want all the column values assigned to begin and end. If so, you need to send a message to the column to return those values: << Get Values. The following should work (assuming that's your intent!).

```
dt = Current Data Table();
selectedCol = dt << Get Selected Columns();
If( Col Mean( eval(selectedCol[1]) ) < Col Mean( eval(selectedCol[2]) ),
begin = selectedCol[1] << Get Values;
end = selectedCol[2] << Get Values;
,
begin = selectedCol[2] << Get Values;
end = selectedCol[1] << Get Values;
);
```

I hope this helps!

Edit: I can see how someone might look at my point about nested functions and say "Wait, Col Mean( selectedCol[1] )' isn't a nested function, so why doesn't that work?" In fact, subscribing is a function, it's just done conveniently with brackets. You could have written:

`Col Mean( Subscript(selectedCol,1) )`

and in this case, the nesting of the function is obvious. What happens when JMP tries to evaluate this bit of code is that Col Mean() is evaluated first, and that function requires a column to operate on. It hits a Subscript() function and doesn't know what to do with it. So, by wrapping Subscript() in Eval() we tell JMP to first process the subscripting (which returns a reference to a column) before it tries to evaluate Col Mean().

`Col Mean( Eval( Subscript( selectedCol,1 ) ) )`

I hope the additional explanation helps!

2 REPLIES 2

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

Hi @john_madden,

Two things I notice here. First, JSL evaluates nested functions from the outside in, meaning you need an Eval() for the reference to the column that is part of your list. Second, if I'm understanding you correctly, you want all the column values assigned to begin and end. If so, you need to send a message to the column to return those values: << Get Values. The following should work (assuming that's your intent!).

```
dt = Current Data Table();
selectedCol = dt << Get Selected Columns();
If( Col Mean( eval(selectedCol[1]) ) < Col Mean( eval(selectedCol[2]) ),
begin = selectedCol[1] << Get Values;
end = selectedCol[2] << Get Values;
,
begin = selectedCol[2] << Get Values;
end = selectedCol[1] << Get Values;
);
```

I hope this helps!

Edit: I can see how someone might look at my point about nested functions and say "Wait, Col Mean( selectedCol[1] )' isn't a nested function, so why doesn't that work?" In fact, subscribing is a function, it's just done conveniently with brackets. You could have written:

`Col Mean( Subscript(selectedCol,1) )`

and in this case, the nesting of the function is obvious. What happens when JMP tries to evaluate this bit of code is that Col Mean() is evaluated first, and that function requires a column to operate on. It hits a Subscript() function and doesn't know what to do with it. So, by wrapping Subscript() in Eval() we tell JMP to first process the subscripting (which returns a reference to a column) before it tries to evaluate Col Mean().

`Col Mean( Eval( Subscript( selectedCol,1 ) ) )`

I hope the additional explanation helps!

Highlighted
##

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

Re: Help with column variables

Thank you, thank you Julian!

That is incredibly helpful !!!!

John