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

- JMP User Community
- :
- Discussions
- :
- How do I reference to a column by column number in jsl when column number is a v...

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

Highlighted

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

Nov 1, 2019 5:21 AM
(1345 views)

Hi,

I'm having trouble subsetting columns. In the code below, I'm looking to create multiple new data tables (and perform some analyses with them- though I deleted that part of the script) from my current table. My current table is formatted with one "X" column (column 1) and several "Y" columns (columns 2 through ncols(dt). I'm having an issue where the columns() function does not recognize icol as a variable representing a number (I assume it's looking for a column named icol). Is there a fix for this?

```
dt=current data table();
For( icol = 2, icol <= ncols(dt) , icol++,
dt << Subset( All rows, columns( 1, icol ))
)
```

1 ACCEPTED SOLUTION

Accepted Solutions

Highlighted

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

Hi @Melissa

try this method,

```
Names Default To Here( 1 );
dt = Current Data Table();
icol = dt << Get Column Names();
For( i = 2, i <= N Items( icol ), i++,
dt1 = dt << subset( all rows, columns( 1, icol[i] ),
output table( "subset - " || Char( icol[i] ) ),
)
);
```

let us know if it works for you.

ron

2 REPLIES 2

Highlighted

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

Hi @Melissa

try this method,

```
Names Default To Here( 1 );
dt = Current Data Table();
icol = dt << Get Column Names();
For( i = 2, i <= N Items( icol ), i++,
dt1 = dt << subset( all rows, columns( 1, icol[i] ),
output table( "subset - " || Char( icol[i] ) ),
)
);
```

let us know if it works for you.

ron

Highlighted
##

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

Re: How do I reference to a column by column number in jsl when column number is a variable?

Thanks! that's exactly what I was looking for.

Article Labels

There are no labels assigned to this post.