cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Don’t miss your chance to experience Discovery Summit Europe at our best available rate! Early bird registration through 31 Oct.
  • Graph Builder Toolbar streamlines interactive graphing. Creates shortcuts on Report and GraphBuilder Helpers toolbars. Download and install the extension.
  • JMP will suspend normal business operations for our Rest and Recharge Day on Friday, October 2, 2026.
    Regular business hours will resume on Monday, October 5, 2026.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
fat_angus
Level III

JSL question - returning a character string into a new column based on values within another column

I almost have this; but can't seem to get it generated in a JSL script. The formula editor is doing almost exactly what I want... but when attempting to do it in a script... I can't seem to get it to work. 

 

Desired result is in column 2; I apply the formula shown in the column editor to get the desired result.  

fat_angus_0-1712362189463.png

//This is what I input into formula editor and it works fine;
item_lst = Words( Substitute( :Input, "/", "/;" ), ";" );
result_str = "";
For( i = 1, i <= N Items( item_lst ), i++,
	If( item_lst[i] == "/",
		result_str = result_str || "N",
		result_str = result_str || "Y"
	)
);
result_str;

When I try to create a new column within a JSL script and the I get the result in column 3. I seem to be nesting incorrectly and I can't seem to find this... 

Here is the jsl code. Any help would be much appreciated.

da = Current Data Table();

da <<New Column("Keystring", Character );
	:Keystring << Set Formula (item_lst = Words(
	Substitute(:Input,
		"/", "/;"
	),
	";"
));

result_str = "";
For( i = 1, i <= N Items( item_lst ), i++,
	If( item_lst[i] == "/",
		result_str = result_str || "N",
		result_str = result_str || "Y"
	)
);
result_str;


  

 

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: JSL question - returning a character string into a new column based on values within another column

Your issue was that you had ")" in a couple of incorrect places.  Here is your code with my modifications

da = Current Data Table();

da << New Column( "Keystring", Character );
:Keystring << Set Formula(
	item_lst = Words( Substitute( :Input, "/", "/;" ), ";" );

	result_str = "";
	For( i = 1, i <= N Items( item_lst ), i++,
		If( item_lst[i] == "/",
			result_str = result_str || "N",
			result_str = result_str || "Y"
		)
	);
	result_str;
);
Jim

View solution in original post

2 REPLIES 2
txnelson
Super User

Re: JSL question - returning a character string into a new column based on values within another column

Your issue was that you had ")" in a couple of incorrect places.  Here is your code with my modifications

da = Current Data Table();

da << New Column( "Keystring", Character );
:Keystring << Set Formula(
	item_lst = Words( Substitute( :Input, "/", "/;" ), ";" );

	result_str = "";
	For( i = 1, i <= N Items( item_lst ), i++,
		If( item_lst[i] == "/",
			result_str = result_str || "N",
			result_str = result_str || "Y"
		)
	);
	result_str;
);
Jim
fat_angus
Level III

Re: JSL question - returning a character string into a new column based on values within another column

Hi Jim... I could swear I did that before... the number of times I checked my semicolons, commas and parentheses... 

 

that said... I thank you... it works perfectly now... 

 

not sure how I spent so much time on this. Too late. 

Recommended Articles