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
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.