cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
Tavuk89
Level II

Standardized Group column attributes

Hello. I'm new to jsl scripts.

From scripting help menu, I can transfrom column attributes but how do I do that for all columns in the group?

It's too clunky to write all 20 columns one by one and I have many grouped columns.

I know its easy to just use standardize attributes without scripting but I'm dealing with joined tables that gets updated frrequently and its not productive to do that all the time.

 

dt << Transform Column( "A");
dt:A << Data Type( Numeric);
dt:A << Modeling Type( "Continuous" );

 

I tried changing Column to Column Group, its doesnt seem to work..

2 ACCEPTED SOLUTIONS

Accepted Solutions
txnelson
Super User

Re: Standardized Group column attributes

I believe this will do what you need:

Names Default To Here( 1 );
dt = Current Data Table();
colNames = dt << get column group( "the group's name" );

For Each( {col}, 
	colNames, Column( dt, col ) << Data Type( Numeric ) << Modeling Type( Continuous ) 
);

Please use the txnelson_0-1703035318583.pngwhen entering JSL.  It allows the readers to have an easier time examining the JSL

 

Jim

View solution in original post

jthi
Super User

Re: Standardized Group column attributes

That script is also using For Each which was also added in JMP16. You would have to convert it into For loop which would look something like this

Local({old dt = Current Data Table()},
	Current Data Table(Data Table("Big Class"));
	collist = old dt << get column group("height etc.");
	For(i = 1, i <= N Items(collist), i++,
		col = collist[i];
		col << Data Type(Numeric) << Set Modeling Type("Nominal");
	);
	Current Data Table(old dt);
);

Depending where the script is being run, it could also be cleaned (at least in my opinion) a bit to something like this

Names Default To Here(1);

dt = Current Data Table(); 
// dt = Open(); // use this if possible

collist = dt << get column group("height etc.");
For(i = 1, i <= N Items(collist), i++,
	col = collist[i];
	col << Data Type(Numeric) << Set Modeling Type("Continuous");
);
-Jarmo

View solution in original post

6 REPLIES 6
txnelson
Super User

Re: Standardized Group column attributes

I believe this will do what you need:

Names Default To Here( 1 );
dt = Current Data Table();
colNames = dt << get column group( "the group's name" );

For Each( {col}, 
	colNames, Column( dt, col ) << Data Type( Numeric ) << Modeling Type( Continuous ) 
);

Please use the txnelson_0-1703035318583.pngwhen entering JSL.  It allows the readers to have an easier time examining the JSL

 

Jim
Tavuk89
Level II

Re: Standardized Group column attributes

Thank you Next time i will use <jsl>

 

I tried the script but i got this alert instead. what shoud i do?

Tavuk89_0-1703139253075.png

 

jthi
Super User

Re: Standardized Group column attributes

That script is also using For Each which was also added in JMP16. You would have to convert it into For loop which would look something like this

Local({old dt = Current Data Table()},
	Current Data Table(Data Table("Big Class"));
	collist = old dt << get column group("height etc.");
	For(i = 1, i <= N Items(collist), i++,
		col = collist[i];
		col << Data Type(Numeric) << Set Modeling Type("Nominal");
	);
	Current Data Table(old dt);
);

Depending where the script is being run, it could also be cleaned (at least in my opinion) a bit to something like this

Names Default To Here(1);

dt = Current Data Table(); 
// dt = Open(); // use this if possible

collist = dt << get column group("height etc.");
For(i = 1, i <= N Items(collist), i++,
	col = collist[i];
	col << Data Type(Numeric) << Set Modeling Type("Continuous");
);
-Jarmo
jthi
Super User

Re: Standardized Group column attributes

You can use Standardize Attributes as your starting point and modify the script it creates as needed. 

I have columns like this and I wish to change height and weight to character type columns

jthi_0-1703058490962.png

Standardize attributes will give me a script like this (from enhanced log)

// Standardize column attributes
Local({old dt = Current Data Table()},
	Current Data Table(Data Table("Big Class"));
	For Each({col, index}, {:height, :weight},
		col << Data Type(Character) << Set Modeling Type("Nominal")
	);
	Current Data Table(old dt);
);

Next search scripting index for column group (or something similar)

jthi_1-1703058572995.png

after small modification (I change data type and modeling type back to numeric)

// Standardize column attributes
Local({old dt = Current Data Table()},
	Current Data Table(Data Table("Big Class"));
	For Each({col, index}, old dt << get column group("height etc."),
		col << Data Type(Numeric) << Set Modeling Type("Continuous")
	);
	Current Data Table(old dt);
);

If you don't know the column group name, the it is back to scripting index

jthi_2-1703058697546.png

 

 

-Jarmo
Tavuk89
Level II

Re: Standardized Group column attributes

Thank you!

How do I get the enhanced log? Is it available in JMP 16? I havent upgraded yet

jthi
Super User

Re: Standardized Group column attributes

Yes, it was added in JMP16 and each version since then is able to capture more actions (and JMP17 has workflow builder).

-Jarmo