cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
Create a Formula Column

Problem

You want to create a new data table column that contains values that are based on the evaluation of a formula. The formula uses the value of another column to determine the value in the new column.

Solution

This solution uses the Big Class sample data table and creates a formula that uses the value of the Age column to determine a resulting category for a new column called Adolescent Phase. If the value of Age is less than or equal to 12, the formula returns "early"; if the value of Age is greater than 12 but less than or equal to 15, the formula returns "mid"; if the value of Age is greater than 15, the formula returns "late".

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

dt << New Column( "Adolescent Phase",
	Character,
	Formula(
		If(
			:age <= 12, "early",
			12 < :age <= 15, "mid",
			"late"
		)
	)
);

Discussion

A formula column can use the values from other columns in the data table, but it does not have to use them. In fact, you can use random number generation JSL functions in formula columns to create random numbers in a data table. Creating formula columns like this is also sometimes known as feature creation.

See Also

Documentation

JSL Cookbook

If you’re looking for a code snippet or design pattern that performs a common task for your JSL project, the JSL Cookbook is for you.

This knowledge base contains building blocks of JSL code that you can use to reduce the amount of coding you have to do yourself.

It's also a great place to learn from the experts how to use JSL in new ways, with best practices.