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

Recding in JSL while keeping most initial values

Hi,

I have a column with probablities. Mostly these are just numbers between 0 and 1. However, for a probablity of 100% I got 100 instead of 1. My idea to fis the issue was simply to ues the recoding function and then replace all occurences of "100" by "1".

The code scnipped I'm using is:

dt << Recode Column (
	:"probability"n,
	{IF( _rcNOW == 100, 1)},
	Target Column (:"probability"n)
);

This works partly, the problem is that all cases where the probability is < 100, the updated column is empty. That's because the IF statement does not know what to do in the case. Is there a way to tell that in that case, it should just keep the orignal value?

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: Recding in JSL while keeping most initial values

I think you can use _rcNOW in your else statement

dt << Recode Column(
	:"probability"n, 
	{If(_rcNOW == 100, 
		1
	, _rcNOW
	)}, 
	Target Column(:"probability"n)
);

but if you just want to change 100 to 1, using Map Value (the most basic recode operation) might be easier. I think you can just do this interactively from Recode menu.

-Jarmo

View solution in original post

3 REPLIES 3
jthi
Super User

Re: Recding in JSL while keeping most initial values

I think you can use _rcNOW in your else statement

dt << Recode Column(
	:"probability"n, 
	{If(_rcNOW == 100, 
		1
	, _rcNOW
	)}, 
	Target Column(:"probability"n)
);

but if you just want to change 100 to 1, using Map Value (the most basic recode operation) might be easier. I think you can just do this interactively from Recode menu.

-Jarmo

Re: Recding in JSL while keeping most initial values

Thanks that worked perfectly! (and looks obvious in hindsight).
Indeed, I could to it interactively w/o problem and I might have to run that on different files, so I prefer a scirpting solution.
What do you mean by "Map Value"? (Or is that the interactive aproach?)

jthi
Super User

Re: Recding in JSL while keeping most initial values

Do it interactively in JMP and JMP will create a script for you. For example I have a table

jthi_0-1717785927445.png

And I wish to change 100 to 1

jthi_1-1717785940218.png

jthi_2-1717785946544.png

JMP creates a script for you

jthi_3-1717785965871.png

And you can clean it up and modify it a bit and have it look like this

dt << Recode Column(
	dt:Prob,
	{Map Value(_rcOrig, {100, 1}, Unmatched(_rcNow))},
	Target Column(:Prob) 
);

JMP basically created this script for me without me writing any JSL.

-Jarmo