cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Image to Table JMP extension imports single or batch images as data tables. Useful to extract curves from pictures or convert image data to curve data to use in analyses like Functional Data Explorer. Download and install the extension.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
Jackie_
Level VII

How to create column formula using a column name from a list

Hi,

 

I want to create a new column in the 2nd JMP table with a formula that simply sums the Columns contain in the list (in the code I've assigned column name to binss.
For Ex: The list contains Column names "39","41","43". I want to create a new Column in the Soft Bin Summary table with addition of all these in the formula 

I can't figure out what I'm doing wrong in going from the list {""} of columns to the reference to the columns.

Any help is much appreciated.

 

Here's the code that I've tried

Names Default To Here( 1 );
Clear Globals();

dt = Data Table( "Untitled 910" );
dt2 = Data Table( "Soft Bin Summary" );

Try( For Each Row( :Yield SummaryBins = Word( 1, :Yield SummaryBins, "[]" ) ) );
grouplist = dt:Yield SummaryBins << get values;

For( i = N Items( grouplist ), i >= 1, i--,
	If( grouplist[i] == "",
		Remove From( grouplist, i, 1 ), 

	));
binss = {}; /// list contaiting bin value
For( i = 1, i <= N Items( grouplist ), i++, 

	If( Contains( grouplist[i], " " ), 

		Insert Into( binss, grouplist[i] )
	)
);

adad = Words( binss[1], " " );
F = Eval Expr( Sum( Expr( adad ) ) );

/// Something doesn't seem to right in the below loop

For( i = 1, i <= N Items( binss ), i++, 	
dt2 << New Column( binss[i], "Numeric", "Continuous", Format( "Percent", 12, 2 ), Formula( Name Expr( F ) ) );); 

 

Thanks,

Jack

 

 

10 REPLIES 10
txnelson
Super User

Re: How to create column formula using a column name from a list

Names Default To Here( 1 );
dt = Data Table( "Condition table" );
dt2 = Data Table( "Soft Bin Summary" );

Current Data Table( dt );

// Rule: Create a new Summary Column for each row in the Condition Table
// that has a value in the Yield SummaryLabel column
For( i = 1, i <= N Rows( dt ), i++,
	If( dt:Yield SummaryLabel[i] != "",
		theString = "";
		k = 1;
		While( Word( k, dt:Yield SummaryBins[i], "[] " ) != "",
			theString = theString || ", :\!"" || Word(
				k,
				dt:Yield SummaryBins[i],
				"[] "
			) || "\!"n";
			k++;
		);
		theString = Substr( theString, 1 );
		Eval(
			Parse(
				"dt2<<new column(\!"" || dt:Yield SummaryLabel[i] ||
				"\!", formula(sum(" || theString ||
				")),Format( \!"Percent\!", 7, 2 ));"
			)
		);
	)
);

 

The only compensation that Community members get for helping other members, is the satisfaction that comes from the members they have helped becoming more self-sufficient.  Cutting and pasting of someone else's working code is not a good way to become self-sufficient. 

Jim

Recommended Articles