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
- :
- Change column data type with special names

- 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

Jan 3, 2018 12:33 PM
(4853 views)

I like to write a script to get the column names that starts with "WIFI" and "BR" and then change the modeling type as "Continuous"). Something like belwo

Current data Table();

col_list = dt << get column names( "WIFI","BR" );

col_list << Set Modeling Type("Continuous");

Can you help me ? Thanks

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

Thanks so much. It works fine.

5 REPLIES 5

Highlighted
##

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

Re: Change column data type with special names

Maybe something like this?

```
Names default to here ( 1 );
dt = Open( "$Sample_data/iris.jmp" );
cols = dt << Get column Names();
for( i = 1, i <= N Items( cols ), i++,
if( contains( uppercase( cols[i] ), "SEPAL" ) |
contains( uppercase( cols[i] ), "WIDTH" )
,
Column( dt, cols[i] ) << Set Modeling Type( "Nominal" );
)
);
```

Highlighted
##

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

Re: Change column data type with special names

I am taking a small amount of liberty with @ih JSL. Since you specified, that you are looking for column names that "begin" with specific string values, I would insure this by specifying that the Contains return value has to be a 1, indicating the value was found in column 1.

```
dt = Open( "$Sample_data/iris.jmp" );
cols = dt << Get column Names();
for( i = 1, i <= N Items( cols ), i++,
if( contains( uppercase( cols[i] ), "SEPAL" ) ==1 |
contains( uppercase( cols[i] ), "WIDTH" ) == 1
,
Column( dt, cols[i] ) << Set Modeling Type( "Nominal" );
)
);
```

You may also choose the following methodology, which I find to actually be more readable

```
Names Default to Here( 1 );
dt = Open( "$Sample_data/iris.jmp" );
cols = dt << Get column Names();
for( i = 1, i <= N Items( cols ), i++,
if( Left( uppercase( cols[i] ), 5 ) == "SEPAL" |
Left( uppercase( cols[i] ), 5 ) == "WIDTH"
,
Column( dt, cols[i] ) << Set Modeling Type( "Nominal" );
)
);
```

Jim

Highlighted
##

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

Re: Change column data type with special names

Good catch @txnelson. Given any more than a simple match I default to regex. Thus I present yet another option:

```
dt = Open( "$Sample_data/iris.jmp" );
cols = dt << Get column Names();
for( i = 1, i <= N Items( cols ), i++,
if( !Is missing(Regex( char( cols[i] ) , "^(sepal|width)(.*)", "\0", IGNORECASE) ),
Column( dt, cols[i] ) << Set Modeling Type( "Nominal" );
)
);
```

Highlighted

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

Thanks so much. It works fine.

Highlighted
##

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

Re: Change column data type with special names

I don't think the response you selected as "The Solution" is the solution.

Jim

Article Labels

There are no labels assigned to this post.