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
Mcc99
Level I

Script to change data type for all columns that contain a string in their header?

I'm trying to write a script to change all the columns with the word "Mean" in their header to numeric data type and continuous modeling type. 

I'm getting the error that "Send Expects Scriptible Object" regarding the last line "cols << data type("numeric")". How would I fix my code? Or is there an easier way to accomplish the same task? 

cols = dt << get column names( string );
For( i = N Items( cols ), i>=1, i--,
	If( Contains( cols[i], "Mean" ),
	 cols << data type("numeric");  
	)
);

I'm using JMP Pro 16. Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: Script to change data type for all columns that contain a string in their header?

You are sending the message to wrong variable. Something like

cols = dt << get column names(string);
For(i = N Items(cols), i >= 1, i--,
	If(Contains(cols[i], "Mean"),
		Column(dt, cols[i] << data type("numeric")
	)
);

should work. I would also rewrite the script a little (use For Each and << Set Data Type) as I think those are easier to read

cols = dt << get column names("String");

For Each({col}, cols,
	If(Contains(col, "Mean"),
		Column(dt, col) << Set Data Type("Numeric");
	);
);
-Jarmo

View solution in original post

2 REPLIES 2
jthi
Super User

Re: Script to change data type for all columns that contain a string in their header?

You are sending the message to wrong variable. Something like

cols = dt << get column names(string);
For(i = N Items(cols), i >= 1, i--,
	If(Contains(cols[i], "Mean"),
		Column(dt, cols[i] << data type("numeric")
	)
);

should work. I would also rewrite the script a little (use For Each and << Set Data Type) as I think those are easier to read

cols = dt << get column names("String");

For Each({col}, cols,
	If(Contains(col, "Mean"),
		Column(dt, col) << Set Data Type("Numeric");
	);
);
-Jarmo
Mcc99
Level I

Re: Script to change data type for all columns that contain a string in their header?

Thanks! That second script works great.