cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Choose Language Hide Translation Bar
shilpa
Level II

JSL error not enough arguments in access or evaluation of 'For'

Hi,

I am beginner in JSL scripting. I need help with the following error. 

 

"not enough arguments in access or evaluation of 'For' "

 

In my code below, I am trying to delete columns that contain certain strings in their column name. I'm not sure where I am making the mistake. 

 

dt = Current Data Table();
col_list = dt << get column names(string);
for(i = 1; i>= N Items (col_list), i++,
If(
Contains(col_list[i], "MTR") | Contains(col_list[i], "AUTO") | Contains(col_list[i], "ProcessCon") | Contains(col_list[i], "Macro") | Contains(col_list[i], "OTH_SP") ),

Remove from(col_list, i)

)
);
dt << delete columns( col_list );

Please let me know. Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions
Jeff_Perkinson
Community Manager Community Manager

Re: JSL error not enough arguments in access or evaluation of 'For'

You've got a semi-colon (;) after the first argument instead of a comma (,).

 

You've also got an extra close parentheses.

 

It should be:

 

dt = Current Data Table();
col_list = dt << get column names( string );
For( i = 1, i >= N Items( col_list ), i++, 
//________^
//comma here, no semi-colon

	If(
		Contains( col_list[i], "MTR" ) | Contains( col_list[i], "AUTO" ) |
		Contains( col_list[i], "ProcessCon" ) | Contains( col_list[i], "Macro" ) |
		Contains( col_list[i], "OTH_SP" )
	), 

	Remove From( col_list, i )
//)
//don't need close parentheses above
);
dt << delete columns( col_list );
-Jeff

View solution in original post

3 REPLIES 3
Jeff_Perkinson
Community Manager Community Manager

Re: JSL error not enough arguments in access or evaluation of 'For'

You've got a semi-colon (;) after the first argument instead of a comma (,).

 

You've also got an extra close parentheses.

 

It should be:

 

dt = Current Data Table();
col_list = dt << get column names( string );
For( i = 1, i >= N Items( col_list ), i++, 
//________^
//comma here, no semi-colon

	If(
		Contains( col_list[i], "MTR" ) | Contains( col_list[i], "AUTO" ) |
		Contains( col_list[i], "ProcessCon" ) | Contains( col_list[i], "Macro" ) |
		Contains( col_list[i], "OTH_SP" )
	), 

	Remove From( col_list, i )
//)
//don't need close parentheses above
);
dt << delete columns( col_list );
-Jeff
shilpa
Level II

Re: JSL error not enough arguments in access or evaluation of 'For'

Hi Jeff, 

 

Thank you. That got rid of the error. However, I must have made a logical error. The code I had, erased all the columns in the data table.

 

Perhaps, I'm making a mistake with delete columns?

 

Instead of "Remove from (col_list, i)", am I allowed to write the following?

 

dt<< delete columns(col_list[i]); ?

 

I'm not sure of the syntax. But my aim is to delete all columns which has "MTR" or "ProcessCon" etc in their column name. 

 

Please let me know. 

shilpa
Level II

Re: JSL error not enough arguments in access or evaluation of 'For'

I was able to get around the issue and below code worked for me to delete columns based on column name.

 

 

Clear Log();

dt = Current Data Table();
col_list = dt << get column names;
For( c = N Cols( dt ), c >= 1, c--,
	If(
		Contains( col_list[c], "MTR" ) | Contains( col_list[c], "AUTO" ) | Contains( col_list[c], "ProcessCon" )
		 | Contains( col_list[c], "Macro" ),
		dt << deleteColumn( c )
	);
);