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

Syntax error with "function" or "for"

Hello JMPers,

 

My (JMP 14.3.0, W10) intention is to write a function that takes a table (dt) and list of unique Lot Numbers (uids) as input, and construct a table by concatenating a copy of dt for each uid, and filling in the appropriate Lot. No. information for each of those spots. The purpose of this is so I can later do join operations on the table. I am in the early part of the JSL learning curve, and I'm encountering the error as follows:

Unexpected "if". Perhaps there is a missing "," or ")". Trying to parse arguments of function "For".

 

I presume I have a syntax issue with either my function or my For loop, but the syntax looks the same to me as other code I have that seems to be running correctly. Any/all advice is most welcome!

 

 

pop_limits_with_uids = Function( {dt, uids},
	For( i = 1, i < N Items( uids ), i++,
		Print( "here" );
		If( i == 1,
			pop_dt = dt << Subset( Output Table( "dt_copy" ), All rows, Selected columns only( 0 ) );
			dt_copy = pop_dt;
			Print( i );
		,
			dt_copy = dt << Subset( Output Table( "dt_copy" ), All rows, Selected columns only( 0 ) )
		);	
		
		Column( dt_copy, "Lot No." )[{1, 2, 3}] = uids[i];	//dt_copy should have 3 rows. Set all 3 Lot No. to latest uid
		
		pop_dt << concatenate( dt_copy, append to first table( 1 ) );	//add to the primary list
	);
	
	Close( dt_copy );
);
 
 
 
Regards,
Scott
1 REPLY 1
Craige_Hales
Super User

Re: Syntax error with "function" or "for"

I don't see a syntax issue in the JSL you posted in JMP 17.

 

Once you get past that issue, whatever it turns out to be, you might want to use some local variables in the function. Something like this:

pop_limits_with_uids = Function( {dt, uids},
	{ i, pop_dt, dt_copy }, // these are local to the function
	For( i = 1, i < N Items( uids ), i++,
		Print( "here" );
		If( i == 1,
			pop_dt = dt << Subset( Output Table( "dt_copy" ), All rows, Selected columns only( 0 ) );
			dt_copy = pop_dt;
			Print( i );
		,
			dt_copy = dt << Subset( Output Table( "dt_copy" ), All rows, Selected columns only( 0 ) )
		);	
		
		Column( dt_copy, "Lot No." )[{1, 2, 3}] = uids[i];	//dt_copy should have 3 rows. Set all 3 Lot No. to latest uid
		
		pop_dt << concatenate( dt_copy, append to first table( 1 ) );	//add to the primary list
	);
	
	Close( dt_copy );
);

there are other ways; this is what works best for me. It won't fix the problem you are currently facing.

Craige