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
- :
- How to create variable names depending on loop num...

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

Sep 17, 2013 3:25 PM
(3109 views)

Hello

I am trying to create variables dynamically depending on the number of times my loop runs. How can I go about doing this?

Example

for(i=1, i<x, i++,

//some code goes here

var || i = current data table(); //This obviously does not work, but I hope you get the idea. I would eventually like to have var1, var2, var3, etc... till the loop is done

)

Does this make sense?

thanks

1 ACCEPTED SOLUTION

Accepted Solutions

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

Sep 17, 2013 3:53 PM
(4236 views)

Solution

Abdulj,

Here is one way using Eval ( Substitute ( ))

// dv = dummy variable

x = 10;

For (i=1, i<=x, i++,

Eval ( Substitute ( Expr (

dv_variable = i;

Show(dv_variable)

),

Expr(dv_variable),

Parse("Variable Name " || Char(i))

))

)

Michael

7 REPLIES

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

Sep 17, 2013 3:53 PM
(4237 views)

Abdulj,

Here is one way using Eval ( Substitute ( ))

// dv = dummy variable

x = 10;

For (i=1, i<=x, i++,

Eval ( Substitute ( Expr (

dv_variable = i;

Show(dv_variable)

),

Expr(dv_variable),

Parse("Variable Name " || Char(i))

))

)

Michael

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

Sep 19, 2013 1:05 PM
(2715 views)

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

Sep 17, 2013 6:21 PM
(2715 views)

Here is an alternate notation:

**For (i=1 ,i<=x ,i++,**

** Eval( Parse( Eval Insert("\[**

** var^i^ = Current Data Table()**

** ]\")))**

**)**

-Dave

-Dave

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

Sep 20, 2013 5:57 AM
(2715 views)

Dave,

I've never seen that syntax before, do the ^ surround any variable to include in text? I would have written:

tmp = "var" || char(i) || " = Current Data Table()";

eval(parse(tmp))

This is obviously less efficient than what you've written.

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

Sep 20, 2013 11:17 AM
(2715 views)

Yes enclose each variable with ^ ... ^ and have the jsl statement enclosed in the **Eval( Parse( Eval Insert("\[** ...** ]\")))** pattern.

For example, the following code sets spec limits for a column:

Open("$SAMPLE_DATA/Big Class.jmp");

cHeight = Column("height");

Column("height") << Set Property( "Spec Limits", {LSL(55), USL(75), Target(65)} );

Let's say we have the following variable assignments that we would like to use:

colName = "height";

lower = 55;

upper = 75;

target = 40;

Then we can write:

Eval( Parse( Eval Insert("\[

Column("^colName^") << Set Property( "Spec Limits", {LSL(^lower^), USL(^upper^), Target(^target^)} );

]\")))

-Dave

-Dave

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

Sep 18, 2013 10:45 AM
(2715 views)

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

Apr 24, 2016 6:53 AM
(2715 views)

oh nice .... thank you very much. Another thing I need to learn in JMP ...