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
- :
- How do I have tabulate iterate through multiple columns using JSL

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

Nov 12, 2015 2:36 PM
(5929 views)

I'm pretty new to JSL and I'm stuck on something that seems like it should work, but it isn't. This is what I'm trying to create:

Here's what the dataset looks like (well, it's fake, but you get the point):

and this is the code I'm trying to use:

top15<<Tabulate(

Add Table(

Column Table( Analysis Columns( :Acc_std ) ),

**for(i=1,**

** i<=nitems(top15<<get column names())-1,**

** i++,**

** Row Table( Grouping Columns( column name(i) ) )**

)

)

);

I'm doing it this way because when I created the tabulate manually the script output was:

Tabulate(

Add Table(

Column Table( Analysis Columns( :Acc_std ) ),

Row Table( Grouping Columns( :A ) ),

Row Table( Grouping Columns( :B ) ),

Row Table( Grouping Columns( :C ) ),

Row Table( Grouping Columns( ) ),

Row Table( Grouping Columns( :E ) )

)

);

instead of writing out each column, I was hoping to just be able to iterate through the columns (using the for loop). Where am I going wrong, or am I completely going down the wrong path here?

Thanks in advance.

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 can either build the required expression in advance (see, for example https://community.jmp.com/message/224888#224888), or add the row tables incrementally, as below.

NamesDefaultToHere**(****1****)**;

// Example table

dt = New Table**(** "Test",

Add Rows**(** **100** **)**,

New Column**(** "A",

Numeric,

"Nominal",

Format**(** "Best", **12** **)**,

Formula**(** Random Integer**(** **4** **)** **)**

**)**,

New Column**(** "B",

Numeric,

"Nominal",

Format**(** "Best", **12** **)**,

Formula**(** Random Integer**(** **5** **)** **)**

**)**,

New Column**(** "Y",

Numeric,

"Continuous",

Format**(** "Best", **12** **)**,

Formula**(** Random Normal**()** **)**

**)**

**)**;

// List of grouping columns

cList = **{**:A, :B**}**;

// Tabulate

tab = dt << **Tabulate****(**Add Table**(** Column Table**(** Analysis Columns**(** :Y **)** **)))**;

// Add grouping columns in cList

For **(**c=**1**, c<=NItems**(**cList**)**, c++,

tab << **AddTable****(**Row Table**(** Grouping Columns**(** cList**[**c**]** **)** **))**;

**)**;

I also note that (for some reason) when I cut and paste the above code into the 'Reply' box the 'Analysis Column' was switched from ':Y' to ':And' (!?)

4 REPLIES 4

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

You can either build the required expression in advance (see, for example https://community.jmp.com/message/224888#224888), or add the row tables incrementally, as below.

NamesDefaultToHere**(****1****)**;

// Example table

dt = New Table**(** "Test",

Add Rows**(** **100** **)**,

New Column**(** "A",

Numeric,

"Nominal",

Format**(** "Best", **12** **)**,

Formula**(** Random Integer**(** **4** **)** **)**

**)**,

New Column**(** "B",

Numeric,

"Nominal",

Format**(** "Best", **12** **)**,

Formula**(** Random Integer**(** **5** **)** **)**

**)**,

New Column**(** "Y",

Numeric,

"Continuous",

Format**(** "Best", **12** **)**,

Formula**(** Random Normal**()** **)**

**)**

**)**;

// List of grouping columns

cList = **{**:A, :B**}**;

// Tabulate

tab = dt << **Tabulate****(**Add Table**(** Column Table**(** Analysis Columns**(** :Y **)** **)))**;

// Add grouping columns in cList

For **(**c=**1**, c<=NItems**(**cList**)**, c++,

tab << **AddTable****(**Row Table**(** Grouping Columns**(** cList**[**c**]** **)** **))**;

**)**;

I also note that (for some reason) when I cut and paste the above code into the 'Reply' box the 'Analysis Column' was switched from ':Y' to ':And' (!?)

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

Re: How do I have tabulate iterate through multiple columns using JSL

That worked perfectly!

Just so that I understand, it looks like you named the tabulate window "tab" and that allowed you to send additional commands to it, correct?

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

Re: How do I have tabulate iterate through multiple columns using JSL

Yes. JMP reports and their constituent parts are essentially objects that you can send messages to. By assigning a reference to an object (in this case 'tab'), you can then do 'Show Properties(tab)' to see what messages that object knows about and can respond to.

Take a look at chapters 10 and 11 of the Scripting Guide ('Help > Books > Scripting Guide') and also 'Help > Scripting Index'.

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

Re: How do I have tabulate iterate through multiple columns using JSL

This is very helpful, thanks!