BookmarkSubscribe
Choose Language Hide Translation Bar
PNash
Occasional Contributor

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?

0 Kudos
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
4 REPLIES 4
Highlighted
Thierry_S
Community Trekker

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
Occasional Contributor

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

Is there a way to script that?

0 Kudos
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