cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar

Select all columns at once from a table

I have multiple tables which contain data imported from csv files. unfortunately not all tables are the same length and vary in length day to day. however id still like to be able to convert all columns to datatype character, is there any command within jmp scripting that would allow me to do this without having to specify individual columns (since i dont know how many columns there will be in total)
1 ACCEPTED SOLUTION

Accepted Solutions

Re: Select all columns at once from a table

The following example script will convert the data type of all columns in the current data table to a data type of Character.  This is simply a more concise suggestion than what was offered earlier in this thread. 

In order to loop through the columns, you do not need to know how many columns there are, nor their names, prior to the For() loop.  The NCol() function returns the number of columns in the data table.  The Column() function allows you to refer to a column by index.

dt = Current Data Table();

For( i = 1, i <= N Col( dt ), i++,
	Column( dt, i ) << Data Type( "Character" )
);

Hope that helps.

Wendy

View solution in original post

5 REPLIES 5

Re: Select all columns at once from a table

you could use a short script that makes a list of all the column names, then iteratively assigns a property to each column.

Re: Select all columns at once from a table

thanks for the reply

Would you have any samplecode that would do that?
Essentially what im trying to do is to convert all columns to "character".
The closest i have got so far is to use this code
_________________________________
dt=DataTable("Log60");
cc=dt<ncols = N Items(cc);

This returns the name of columns which are "numeric"
_________________________________

The scripting guide then says to use this type of loop to select all the columns listed from the code above
________________________
for(i=1,i<=ncols,i++,
cc(i)<________________________

but this one doesnt work for me - it says invalid row number -1
XanGregg
Staff

Re: Select all columns at once from a table

It works for me, using "cc[ i ]" instead of "cc(i)" . Do you have a column called cc or i that might be conflicting with the variables? Try cc[ i ]<
Edit: The forum software seems to use square brackets for styling, so the message got corrupted. Trying with a space.


Message was edited by: xan@jmp

Re: Select all columns at once from a table

Give this a shot

dt=current data table();
::cc = ::dt << Get Column Names( Continuous );
::ncols = N Items( ::cc );
For( ::i = 1, ::i <= ::ncols, ::i++,
::name = ::cc[::i];
::cc[::i] << Data Type( Character );
Current Data Table() << Run Formulas;
);

Re: Select all columns at once from a table

The following example script will convert the data type of all columns in the current data table to a data type of Character.  This is simply a more concise suggestion than what was offered earlier in this thread. 

In order to loop through the columns, you do not need to know how many columns there are, nor their names, prior to the For() loop.  The NCol() function returns the number of columns in the data table.  The Column() function allows you to refer to a column by index.

dt = Current Data Table();

For( i = 1, i <= N Col( dt ), i++,
	Column( dt, i ) << Data Type( "Character" )
);

Hope that helps.

Wendy