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
- :
- Set Formula Loop - Using a column string & variabl...

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
- Permalink
- Email to a Friend
- Report Inappropriate Content

Feb 10, 2017 10:20 AM
(2076 views)

I have two variables that are used to define 15 columns total. They are a = {"1", "2", "3", "4", "5"} and b = {"1", "2", "3"}. Currently there are 15 columns that are already created with the notation of Column("11"), Column("12"), Column("13"), Column("21"), aka Column(b[1] || a[1]), Column(b[1] || a[2]), etc...

I averaged the first 6 rows of those 15 existing columns and placed it into an array of size 15. I called this array "ave".

So ave[1] would be the average of the first 6 rows in Column("11"), ave[2] would be the average of the first 6 rows in Column("12"), etc...

Now, what I would like to do is create 15 new columns prefixed with "D" using both 'a' & 'b' arrays. Also, have a formula set for those columns that takes the existing column - the average 6 rows of that column.

For example, the formula for Column("D11") would be the following:

:Name("11") - ave[1]

Column("D12") would be the following:

:Name("12") - ave[2]

My Code:

index = 1;

For( i = 3, i > 0, i--, For( j = 5, j > 0, j--, at << Add Multiple Columns( "D" || b[i] || a[j], 1, numeric, continuous, ); F = Eval Expr(expr(ave[index])); Column( "D" || b[i] || a[j] ) << Set Formula( :Name("11")-Name Expr(F) ); index = index + 1; ); );

The code above does not work when I attempt to increment the index variable through the 15 averaged values stored in "ave". The other problem is I need to iterate through :Name("11"), :Name("12"), etc. through all combinations of a & b in the formula. I almost need a way to set the formula in the following manner:

:Name(b[i] || a[i])

However, :Name must use a string with quotes between them and won't let you do it that way.

I tried multiple methods with parse, eval, etc. but with no luck.

Any help would be greatly appreciated!

Thank you!

Solved! Go to Solution.

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Feb 10, 2017 11:32 AM
(4126 views)

Solution

Here is a piece of JSL that will work. It uses a method where the exact character string of what the required command needs to be is generated, and then Eval(Parse()) to run the code

```
index = 1;
;
For( i = 3, i > 0, i--,
For( j = 5, j > 0, j--,
Eval(
Parse(
"at << New Column(\!"D" || b[i] || a[j] ||
"\!",1,numeric,continuous,Formula( :Name( \!""
|| Char( index + 10 ) || "\!" ) - " || Char( ave[index] ) || "));"
)
);
index = index + 1;
);
);
```

Jim

2 REPLIES

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Feb 10, 2017 11:32 AM
(4127 views)

Here is a piece of JSL that will work. It uses a method where the exact character string of what the required command needs to be is generated, and then Eval(Parse()) to run the code

```
index = 1;
;
For( i = 3, i > 0, i--,
For( j = 5, j > 0, j--,
Eval(
Parse(
"at << New Column(\!"D" || b[i] || a[j] ||
"\!",1,numeric,continuous,Formula( :Name( \!""
|| Char( index + 10 ) || "\!" ) - " || Char( ave[index] ) || "));"
)
);
index = index + 1;
);
);
```

Jim

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Feb 10, 2017 12:06 PM
(2060 views)