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
lwx228
Level VIII

I can't even do this simple replace!

Not found in the script index, please finish with JSL.Thank you very much!

 

2018-09-04_18-28-59.png

5 ACCEPTED SOLUTIONS

Accepted Solutions
ian_jmp
Staff

Re: I can't even do this simple replace!

You could use data table subscripting:

 

NamesDefaultToHere(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
Wait(3);
maleRows = Loc(dt[0, "sex"], "M");
dt[maleRows, "sex"] = "boy";

View solution in original post

lwx228
Level VIII

Re: I can't even do this simple replace!

I've tried to write JSL in a way that only works with perfectly matched substitutions, but if you don't want to replace only a few characters, how do you write JSL?Thank you!

 

2018-09-04_21-38-19.png

View solution in original post

txnelson
Super User

Re: I can't even do this simple replace!

This is one way to do it

dt = Current Data Table();
dt:class[dt << get rows where( dt:class == "A1" )] = "A9";
Jim

View solution in original post

ian_jmp
Staff

Re: I can't even do this simple replace!

txnelson
Super User

Re: I can't even do this simple replace!

That is not all the ways it  can be coded in JSL to accomplish what you want, but Ian's suggestion is what I would have also suggested as the solution.

Jim

View solution in original post

14 REPLIES 14
ian_jmp
Staff

Re: I can't even do this simple replace!

You could use data table subscripting:

 

NamesDefaultToHere(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
Wait(3);
maleRows = Loc(dt[0, "sex"], "M");
dt[maleRows, "sex"] = "boy";
lwx228
Level VIII

Re: I can't even do this simple replace!

It seems to be quite different from the VBA approach.thank you!
lwx228
Level VIII

Re: I can't even do this simple replace!

I've tried to write JSL in a way that only works with perfectly matched substitutions, but if you don't want to replace only a few characters, how do you write JSL?Thank you!

 

2018-09-04_21-38-19.png

txnelson
Super User

Re: I can't even do this simple replace!

This is one way to do it

dt = Current Data Table();
dt:class[dt << get rows where( dt:class == "A1" )] = "A9";
Jim
lwx228
Level VIII

Re: I can't even do this simple replace!

If this is the new case, this JSL is not very efficient.Can the code be improved for the new instance?Thank you!

 

 

2018-09-04_22-14-58.png

ian_jmp
Staff

Re: I can't even do this simple replace!

If I understand correctly, consider using the 'Match()' JSL expression. I generated the code below by using 'Cols > Recode':

 

Screen Shot 2018-09-03 at 15.29.02.png

and inspecting the JSL for the resulting formula column. And, 'yes', JSL is very different from VBA. You should look at 'Help > Books > Scripting Guide' and/or consider some training.

 

NamesDefaultToHere(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
Wait(3);
dt << New Column( "Age 2",
					Character,
					"Ordinal",
					Formula(
						Match( :age,
							12, "Twelve",
							13, "Thirteen",
							14, "Fourteen",
							15, "Fifteen",
							16, "Sixteen",
							17, "Seventeen",
							Format( :age, "Fixed Dec", 5, 0 )
						)
					)
				);
lwx228
Level VIII

Re: I can't even do this simple replace!

I'm so sorry!Maybe the example I gave is not appropriate and misleading.

I just want to replace some of the specified characters with others in the same column.That is the manual interface function, just want to use JSL implementation.

The VBA implementation in excel is simple:Selection.Replace What:="1", Replacement:="9", LookAt:=xlPart

I just want the effect of this simple trade effect.But I don't have the corresponding code in JSL.Thank you!
lwx228
Level VIII

Re: I can't even do this simple replace!

This is the result of the substitution in the case of "Match entire cell value" the multiple checkbox is not selected.Thank you!

 

2018-09-04_22-14-58.png

lwx228
Level VIII

Re: I can't even do this simple replace!

It's just a matter of replacing some characters in a cell with JSL.