Share your ideas for the JMP Scripting Unsession at Discovery Summit by September 17th. We hope to see you there!
Choose Language Hide Translation Bar
Highlighted
ileshem
Level III

JSL, Using IF formula and Else value

Hello,

I have a table:

NameScoreReasonScore2
John100Test 
Dan95HW 
Elli92Sick 

I want to add a JSL formula to "Score2" column which takes the value from "Score" unless there is the word "Sick" in the "Reason" column:

NameScoreReasonScore 2
John100Test100
Dan95HW95
Elli92Sick100


Below is what I have but it doesn't perform the Else as I need it to:

dt1 <<new column ("Score2",
	Numeric,
	"Continuous", formula (If( :Reason == "Sick",
	"100",
	:Score
))

	
		
	);


Thank you in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
txnelson
Super User

Re: JSL, Using IF formula and Else value

You are creating a numeric column, but you are trying to give it a character string column value of "100".  By placing quotes around the 100, you are telling it to make the value a character string.  Leave the quotes out to assign a numeric value.

dt1 << New Column( "Score2",
	Numeric,
	"Continuous",
	formula( If( :Reason == "Sick", 100, :Score ) )
);

There is also a possible problem if the column Score is not a numeric column in your data table.  If it is a character column, change your code to:

dt1 << New Column( "Score2",
	Numeric,
	"Continuous",
	formula( If( :Reason == "Sick", 100, num( :Score ) ) )
);
Jim

View solution in original post

1 REPLY 1
Highlighted
txnelson
Super User

Re: JSL, Using IF formula and Else value

You are creating a numeric column, but you are trying to give it a character string column value of "100".  By placing quotes around the 100, you are telling it to make the value a character string.  Leave the quotes out to assign a numeric value.

dt1 << New Column( "Score2",
	Numeric,
	"Continuous",
	formula( If( :Reason == "Sick", 100, :Score ) )
);

There is also a possible problem if the column Score is not a numeric column in your data table.  If it is a character column, change your code to:

dt1 << New Column( "Score2",
	Numeric,
	"Continuous",
	formula( If( :Reason == "Sick", 100, num( :Score ) ) )
);
Jim

View solution in original post

Article Labels