cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Sign-in to the JMP Community will be unavailable intermittently Dec. 6-7 due to a system update. Thank you for your understanding!
  • We’re retiring the File Exchange at the end of this year. The JMP Marketplace is now your destination for add-ins and extensions.
  • JMP 19 is here! Learn more about the new features.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
PNash
Level II

Changing data type and modeling type for multiple columns?

I have 8 columns that I need to change data type, modeling type, and format on, is there any way that I can do it as a grouping?  Or do I need to write my script for each individual column?

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Changing data type and modeling type for multiple columns?

You will need to use a For() loop and loop across the variables in question and change the values.

 

dt = open("$SAMPLE_DATA/big class.jmp");

colList = dt << get column names(numeric);

For(i=1,i<=n items(colList), i++,
column(dt, colList[i]) << data type("numeric");
);
Jim

View solution in original post

4 REPLIES 4
Thierry_S
Super User

Re: Changing data type and modeling type for multiple columns?

Hi,
Select all 8 columns, right-click on the header, choose Standardize Attributes, and then choose the attribute you wish to change (e.g. format, modeling type...)
Thierry R. Sornasse
PNash
Level II

Re: Changing data type and modeling type for multiple columns?

Is there a way to script that?

txnelson
Super User

Re: Changing data type and modeling type for multiple columns?

You will need to use a For() loop and loop across the variables in question and change the values.

 

dt = open("$SAMPLE_DATA/big class.jmp");

colList = dt << get column names(numeric);

For(i=1,i<=n items(colList), i++,
column(dt, colList[i]) << data type("numeric");
);
Jim

Re: Changing data type and modeling type for multiple columns?

An alternate to @txnelson's solution is shown below.  The Get Column Reference message returns a list of references to the columns using the Column() function.  It does not accept the same arguments that Get Column Names does.  Instead, it accepts a list of column names or a matrix. 

 

By using Get Column Names as the argument, you can supply the desired list of column names to Get Column Reference.  Because the resulting list is a list of column references, the Data Type message can be sent to the list.

 

This example captures a list of column references for all numeric columns in the table and then changes the data type to character.

 

dt = Open( "$SAMPLE_DATA\Big Class.jmp" );

//returns {Column( "age" ), Column( "height" ), Column( "weight" )}
colRefs = dt << Get Column Reference( dt << Get Column Names( "numeric" ) );  

colRefs << Data Type( "Character" );

I hope this is helpful!

 

Wendy

Recommended Articles