Choose Language Hide Translation Bar
Highlighted
robot
Community Trekker

Define Column Formula from User Input

Hi,

I am trying to define a new column formula from user input.  I have tried different combinations of Eval(), Eval Insert(), and Parse() without success.  Input can either be columns or lists of columns, plus a scalar.  Below is a minimal example.  Any suggestions?  I am using JMP14, but I hope the solution will work for JMP12 and above.

 

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

// Define new column.
dt << New Column( "Mean for Each Age and Sex Group",
	Formula( Col Mean( :height, :age, :sex ) )
);

// Define user input.
a = 2;
c1 = :height;
c2 = {:age, :sex};

// Define new column from user input.
dt << New Column( "Mean for Each Age and Sex Group 2",
	Formula( Col Mean( a * c1, c2 ) )
);
0 Kudos
1 ACCEPTED SOLUTION

Accepted Solutions
robot
Community Trekker

Re: Define Column Formula from User Input

With help from @ih's input, here is a solution for anyone interested...

 

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

// Define user input.
a = 2;
c1 = Column( "height" );
c2 = {:age, :sex};

// Define new column from user input.
input = Concat( "As Column( \!"", c1 << Get Name, "\!" )" );
If( N Items( c2 ) > 0,
	For( i = 1, i <= N Items( c2 ), i++,
		input = Insert( input, Concat( ", ", "As Column( \!"", Char( c2[i] ), "\!" )" ) )
	)
);
Eval( Parse( Eval Insert( "dt << New Column( \!"Mean for Each Age and Sex Group 2\!", Formula( ^a^ * Col Mean( ^input^ ) ) )" ) ) );

View solution in original post

3 REPLIES 3
ih
ih
Community Trekker

Re: Define Column Formula from User Input

I am not totally sure what formula you want in the newly created column from user input, but take a look at this JSL Cookbook article, it gives examples of several different methods of constructing your new column formula.

robot
Community Trekker

Re: Define Column Formula from User Input

Thanks!  Very useful page.

0 Kudos
robot
Community Trekker

Re: Define Column Formula from User Input

With help from @ih's input, here is a solution for anyone interested...

 

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

// Define user input.
a = 2;
c1 = Column( "height" );
c2 = {:age, :sex};

// Define new column from user input.
input = Concat( "As Column( \!"", c1 << Get Name, "\!" )" );
If( N Items( c2 ) > 0,
	For( i = 1, i <= N Items( c2 ), i++,
		input = Insert( input, Concat( ", ", "As Column( \!"", Char( c2[i] ), "\!" )" ) )
	)
);
Eval( Parse( Eval Insert( "dt << New Column( \!"Mean for Each Age and Sex Group 2\!", Formula( ^a^ * Col Mean( ^input^ ) ) )" ) ) );

View solution in original post