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

Create and populates new columns based categories in an existing column

Hello,

 

I'm trying to build a quick query in which a categorical column (test_article) is used to  create a series of column which contains only a subset of the information. If the script works as intended, the table would end up with 2 new columns (PBS vs ...).  

 

test_articlemeasurementPBS vs 709547PBS vs 709139
PBS1.23PBSPBS
PBS1.456PBSPBS
7095474.56709547EXCLUDE

709139

5.02EXCLUDE709139
7091396.02EXCLUDE709139
7095474.57709547EXCLUDE

 

I've tried the following script:

 

NamesDefaultToHere(1);
dt=current data table();

row = Associative Array( :test_article ) << Get Keys;
nc=N items (row);
For( i = 1, i <= nc, i++,
		new column("PBS vs "|| row[i],"Character", "Nominal", Formula(If( :test_article == "PBS", :test_article,
	If( :test_article == row[i],
		"test",
		"EXCLUDE"
	)
))));

Somehow, it does not populate any values in the new columns with the exception of 'PBS'.

 

Any suggestions?

 

Thanks a lot

 

Sebastien

2 ACCEPTED SOLUTIONS

Accepted Solutions
txnelson
Super User

Re: Create and populates new columns based categories in an existing column

The primary issue you are having is that within the definition of a formula, one can not have items that need to be evaluated.  JMP thinks everything within the formula definition is to be evaluated only when the formula is executed.

Therefore, the formula that is passed into the New Column definition, must be complete in it's syntax.  The modification of your code below works with your sample data table.

Names Default To Here( 1 );
dt = Current Data Table();

row = Associative Array( :test_article ) << Get Keys;
nc = N Items( row );
For( i = 1, i <= nc, i++,
	Eval(
		Parse(
			"New Column( \!"PBS vs " || row[i] ||
			"\!",
		Character,
		Nominal,
		Formula(
		if (Row() == 1, theTest = \!""
			 || row[i] ||
			"\!"); 
			If( :test_article == \!"PBS\!",
				zip=:test_article,
				If( :test_article == theTest,
					zip=\!"test\!",
					zip=\!"EXCLUDE\!"
				)
			);
			zip
		)
	)
);"
		)
	)
);

theformulas.PNG

Jim

View solution in original post

Jeff_Perkinson
Community Manager Community Manager

Re: Create and populates new columns based categories in an existing column

You need to get the value of row[i] into the formula. JMP doesn't evaluate expressions inside the Formula() part of the New Column() message.

 

You can use Substitute() to get the actual value of row[i] into the formula.

 

Names Default To Here( 1 );
dt = Current Data Table();

row = Associative Array( :test_article ) << Get Keys;
nc = N Items( row );
For( i = 1, i <= nc, i++,
	Eval(
		Substitute(
				Expr(
					New Column( "PBS vs " || row[i],
						"Character",
						"Nominal",
						Formula( If( :test_article == "PBS" | :test_article == ri, :test_article, "EXCLUDE" ) )
					)
				),
			Expr( ri ), Eval( row[i] )
		)
	)
);
-Jeff

View solution in original post

4 REPLIES 4
txnelson
Super User

Re: Create and populates new columns based categories in an existing column

The primary issue you are having is that within the definition of a formula, one can not have items that need to be evaluated.  JMP thinks everything within the formula definition is to be evaluated only when the formula is executed.

Therefore, the formula that is passed into the New Column definition, must be complete in it's syntax.  The modification of your code below works with your sample data table.

Names Default To Here( 1 );
dt = Current Data Table();

row = Associative Array( :test_article ) << Get Keys;
nc = N Items( row );
For( i = 1, i <= nc, i++,
	Eval(
		Parse(
			"New Column( \!"PBS vs " || row[i] ||
			"\!",
		Character,
		Nominal,
		Formula(
		if (Row() == 1, theTest = \!""
			 || row[i] ||
			"\!"); 
			If( :test_article == \!"PBS\!",
				zip=:test_article,
				If( :test_article == theTest,
					zip=\!"test\!",
					zip=\!"EXCLUDE\!"
				)
			);
			zip
		)
	)
);"
		)
	)
);

theformulas.PNG

Jim
Sburel
Level IV

Re: Create and populates new columns based categories in an existing column

Works like a charm!

Thanks
Jeff_Perkinson
Community Manager Community Manager

Re: Create and populates new columns based categories in an existing column

You need to get the value of row[i] into the formula. JMP doesn't evaluate expressions inside the Formula() part of the New Column() message.

 

You can use Substitute() to get the actual value of row[i] into the formula.

 

Names Default To Here( 1 );
dt = Current Data Table();

row = Associative Array( :test_article ) << Get Keys;
nc = N Items( row );
For( i = 1, i <= nc, i++,
	Eval(
		Substitute(
				Expr(
					New Column( "PBS vs " || row[i],
						"Character",
						"Nominal",
						Formula( If( :test_article == "PBS" | :test_article == ri, :test_article, "EXCLUDE" ) )
					)
				),
			Expr( ri ), Eval( row[i] )
		)
	)
);
-Jeff
Sburel
Level IV

Re: Create and populates new columns based categories in an existing column

Also works like a charm.

Thanks a lot