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
Mauro_Gerber
Level IV

Script the "Group Similar Values" function in the Recode platform with JSL

I want to automate a recode function in JSL but I can not found any documentation on how to achieve it.
No luck in this forum, JMP search function or the scripting index. The workflow recorder and the log file only gets the final result (lock-up table) and its the same with the save script to data table function.

 

Mauro_Gerber_0-1720589195844.png 

If possible to hand over some of those settings if possible but is not important in a first step:

Mauro_Gerber_1-1720589322267.png

 

Best regards

         Mauro

"I thought about our dilemma, and I came up with a solution that I honestly think works out best for one of both of us"
- GLaDOS
1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: Script the "Group Similar Values" function in the Recode platform with JSL

Yeah, seems like Choose Closest is doing some weird things when it is inside a loop. For example this didn't seem to work without using Eval(EvalExpr()) as it was matching abcabcb with abcabca if run inside a loop (if you run it manually until failure, the result was ok).

 

Below is my attempt on something like this (I think Group Choose Closest or something similar would be a good idea for Wish List which would do what Recode is doing)

names default to here(1);

dt = Open("$DOWNLOADS/Test_Table.jmp");
dt << new column("Ones", Numeric, Continuous, Set Each Value(1)); // summarize...

Summarize(dt, groups = By(:Column 1), counts = Sum(:Ones));

aa_matches = Associative Array(groups);

groups = groups[Rank(Ranking(counts))];
aa_matches[Reverse(groups)[1]] = Reverse(groups)[1]; // highest is group with itself

str_a = Remove From(groups, 1)[1];
While(N Items(groups) > 0,
	Eval(EvalExpr(
		str_b = Choose Closest(Expr(str_a), Expr(groups), Ignore Case(1), Ignore Whitespace(1), Ignore Nonprintable(1), Max Edit Count(2), Max Edit Ratio(0.25));	
	));
	aa_matches[str_a] = str_b;
	str_a = Remove From(groups, 1)[1];
);

dt << New Column("Recoded", Character, Nominal, Set Each Value(
	aa_matches[:Column 1];
));
-Jarmo

View solution in original post

3 REPLIES 3
jthi
Super User

Re: Script the "Group Similar Values" function in the Recode platform with JSL

I think you might have to build your own grouping using Choose Closest(). It seems to have MOST of the same options so maybe JMP is using something similar which it isn't recording (I think there are many other things recode isn't recording either).

jthi_0-1720590137767.png

 

-Jarmo
Mauro_Gerber
Level IV

Re: Script the "Group Similar Values" function in the Recode platform with JSL

I made a small script using Choose Closest() but now run into a problem that it only executes once within any form of loop.

Wait didn't help and I tried a lot of scenarios. As long I execute Choose Closest() multiple times in a loop, it gives back the same string regardless of the input.

 

Outside / after the loop, it works fine (again).

 

I added a test setup and will make a ticket at JMP Support.

"I thought about our dilemma, and I came up with a solution that I honestly think works out best for one of both of us"
- GLaDOS
jthi
Super User

Re: Script the "Group Similar Values" function in the Recode platform with JSL

Yeah, seems like Choose Closest is doing some weird things when it is inside a loop. For example this didn't seem to work without using Eval(EvalExpr()) as it was matching abcabcb with abcabca if run inside a loop (if you run it manually until failure, the result was ok).

 

Below is my attempt on something like this (I think Group Choose Closest or something similar would be a good idea for Wish List which would do what Recode is doing)

names default to here(1);

dt = Open("$DOWNLOADS/Test_Table.jmp");
dt << new column("Ones", Numeric, Continuous, Set Each Value(1)); // summarize...

Summarize(dt, groups = By(:Column 1), counts = Sum(:Ones));

aa_matches = Associative Array(groups);

groups = groups[Rank(Ranking(counts))];
aa_matches[Reverse(groups)[1]] = Reverse(groups)[1]; // highest is group with itself

str_a = Remove From(groups, 1)[1];
While(N Items(groups) > 0,
	Eval(EvalExpr(
		str_b = Choose Closest(Expr(str_a), Expr(groups), Ignore Case(1), Ignore Whitespace(1), Ignore Nonprintable(1), Max Edit Count(2), Max Edit Ratio(0.25));	
	));
	aa_matches[str_a] = str_b;
	str_a = Remove From(groups, 1)[1];
);

dt << New Column("Recoded", Character, Nominal, Set Each Value(
	aa_matches[:Column 1];
));
-Jarmo