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
- :
- Copying column properties from one data table to another

- 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

Oct 15, 2014 1:38 PM
(15652 views)

Does anyone have a JSL script that will copy column properties from one data table to 'same name' columns in another data table?

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

Created:
Oct 21, 2014 1:22 PM
| Last Modified: Sep 18, 2017 6:32 AM
(19116 views)
| Posted in reply to message from lou 10-15-2014

Lou,

The following demonstrates how you can copy the column properties from one table to another, assuming the column names are the same.

```
dt = Open( "$SAMPLE_DATA\Tiretread.jmp" );
colNames = dt << Get Column Names( String );
nt = New Table( "New Tires",
New Column( "ABRASION", Numeric, Continuous, Format( "Best", 10 ) ),
New Column( "MODULUS", Numeric, Continuous, Format( "Best", 10 ) ),
New Column( "ELONG", Numeric, Continuous, Format( "Best", 10 ) ),
New Column( "HARDNESS", Numeric, Continuous, Format( "Best", 10 ) ),
New Column( "SILICA", Numeric, Continuous, ),
New Column( "SILANE", Numeric, Continuous, Format( "Best", 10 ) ),
New Column( "SULFUR", Numeric, Continuous, Format( "Best", 10 ) ),
New Column( "Pred Formula ABRASION", Numeric, Continuous, Format( "Best", 10 ) ),
New Column( "Pred Formula MODULUS", Numeric, Continuous, Format( "Best", 10 ) ),
New Column( "Pred Formula ELONG", Numeric, Continuous, Format( "Best", 10 ) ),
New Column( "Pred Formula HARDNESS", Numeric, Continuous, Format( "Best", 10 ) )
);
For( i = 1, i <= N Cols( dt ), i++,
colProps = Column( dt, colNames ) << Get Column Properties;
Column( nt, colNames ) << Add Column Properties( colProps );
);
```

Wendy

7 REPLIES 7

Highlighted

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

Created:
Oct 21, 2014 1:22 PM
| Last Modified: Sep 18, 2017 6:32 AM
(19117 views)
| Posted in reply to message from lou 10-15-2014

Lou,

The following demonstrates how you can copy the column properties from one table to another, assuming the column names are the same.

```
dt = Open( "$SAMPLE_DATA\Tiretread.jmp" );
colNames = dt << Get Column Names( String );
nt = New Table( "New Tires",
New Column( "ABRASION", Numeric, Continuous, Format( "Best", 10 ) ),
New Column( "MODULUS", Numeric, Continuous, Format( "Best", 10 ) ),
New Column( "ELONG", Numeric, Continuous, Format( "Best", 10 ) ),
New Column( "HARDNESS", Numeric, Continuous, Format( "Best", 10 ) ),
New Column( "SILICA", Numeric, Continuous, ),
New Column( "SILANE", Numeric, Continuous, Format( "Best", 10 ) ),
New Column( "SULFUR", Numeric, Continuous, Format( "Best", 10 ) ),
New Column( "Pred Formula ABRASION", Numeric, Continuous, Format( "Best", 10 ) ),
New Column( "Pred Formula MODULUS", Numeric, Continuous, Format( "Best", 10 ) ),
New Column( "Pred Formula ELONG", Numeric, Continuous, Format( "Best", 10 ) ),
New Column( "Pred Formula HARDNESS", Numeric, Continuous, Format( "Best", 10 ) )
);
For( i = 1, i <= N Cols( dt ), i++,
colProps = Column( dt, colNames ) << Get Column Properties;
Column( nt, colNames ) << Add Column Properties( colProps );
);
```

Wendy

Highlighted
##

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

Re: Copying column properties from one data table to another

Thank you for your help. I was trying to iterate through the two tables, but did not have the correct commands.

It seems like this will work as long as the two tables have the same columns, in the same order. Is this correct?

Lou

Highlighted
##

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

Re: Copying column properties from one data table to another

Created:
Oct 22, 2014 2:59 AM
| Last Modified: Sep 18, 2017 6:33 AM
(14971 views)
| Posted in reply to message from lou 10-21-2014

A "quick fix": Put the second line of the loop inside *Try()* to avoid an error if any columns are missing in the new table (column order should not matter here).

`Try( Column( nt, colNames[i] ) << Add Column Properties( colProps ) );`

Highlighted
##

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

Re: Copying column properties from one data table to another

Thanks for your help. That did the trick! My new table will always be a subset of the ‘master’, and the ‘try’ statement does resolve this issue.

Lou

Highlighted
##

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

Re: Copying column properties from one data table to another

Created:
Sep 18, 2017 6:18 AM
| Last Modified: Sep 18, 2017 6:34 AM
(13734 views)
| Posted in reply to message from Wendy_Murphrey 10-21-2014

Hi,

I found this relatively old post and tried to apply the solution to a script I'm doing, but I get the following error message in the debbugger:

"Formula has reference to column or table variable in a different table that cannot be found to be remapped to this table"

My situation is a bit more simple in that I'm only trying to copy the properties of a single column

```
colProps = Column( dt, "Response Predictor" ) << Get Column Properties;
Column( dtparms, "Formula" ) << Add Column Properties( colProps );
```

Any idea what I'm doing wrong?

Johan

Highlighted
##

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

Re: Copying column properties from one data table to another

Created:
Sep 18, 2017 6:58 AM
| Last Modified: Sep 18, 2017 7:07 AM
(13715 views)
| Posted in reply to message from JPKO 09-18-2017

The error message would imply that your new formula coulumn involves one or more columns that are not present in the same table. Are you sure that all the colums required to compute the formula values are in the new table?

Highlighted
##

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

Re: Copying column properties from one data table to another

I'm an idiot. Thank you for hepling me realise that:-)

Article Labels

There are no labels assigned to this post.