Choose Language Hide Translation Bar
Highlighted

## How do I create a custom transform function that takes multiple columns as inputs?

The scripting guide is pretty useful in describing how to make new custom transform functions, but it's not very clear on how to handle multiple columns.

How do I create a custom transform function that takes multiple columns as inputs?  E.g., if I select an X, a Y, and a Z columns and want to take the RSS (root-sum-squared) of those three columns?

Also, if the order matters, how is that order set?  Is it the order that the columns are selected in?

9 REPLIES 9
Highlighted

## Re: How do I create a custom transform function that takes multiple columns as inputs?

I think that a Custom Function is a better choice for your case. The Custom Transform is restricted to a single input. The Custom Function is not restricted in this way.

``````funcDef = Function( {x, y, z}, Sqrt( Sum( x^2, y^2, z^2 ) ) );

description = "This function returns the root sum squared of three numbers.";

// examples can be multiple statements inside expr()
ex2 = Expr(
dt = Open( "\$SAMPLE_DATA/Big Class.jmp" );
);

parmHint1 = "x value";
parmHint2 = "y value";
parmHint3 = "z value";

/* create function using variables
the commands can also be accepted as arguments in New Custom Function */

// expr() Examples need to be passed inside NameExpr()
newAdd << Example( Name Expr( ex2 ) );
newAdd << Parameter( "Number", parmHint1 );
newAdd << Parameter( "Number", parmHint2 );
newAdd << Parameter( "Number", parmHint3 );

newAdd << Formula Category( "NumberStuff" );

The expression inside your function might include logic to address any need for proper order.

Learn it once, use it forever!
Highlighted

## Re: How do I create a custom transform function that takes multiple columns as inputs?

Thanks for the response, Mark! A couple quick follow-on questions:

1. I know JMP *supports* multi-column transform functions -- is it just that it doesn't support multi-column *custom* transforms yet?

2. Your function takes 3 arguments -- is it possible to define a function that takes an arbitrary number of arguments?
Highlighted

## Re: How do I create a custom transform function that takes multiple columns as inputs?

I avoid anything in double quotation marks. They usually have no lasting value. JMP provides custom functions and custom transforms. Why not use them as they were intended?

You could always use a list parameter instead of a scalar parameter if your function must work with a variable number of arguments.

Learn it once, use it forever!
Highlighted

## Re: How do I create a custom transform function that takes multiple columns as inputs?

I'll look up list parameters, thx.

No clue what you're talking about on the double quotation marks, or the basis of the comment about JMP providing custom functions and transforms.
Highlighted

## Re: How do I create a custom transform function that takes multiple columns as inputs?

Here is a new function that takes a list and returns the same computation.

``````Names Default to Here( 1 );

// example
my numbers = List( 1, 2, 3, 4, 5 );

// define it
funcDef = Function( { number }, { i, sum },
If( Is List( number ),
Sqrt( Summation( i = 1, N Items( number ), number[i]^2 ) ),
.
);
);

// test it
Show( funcDef( my numbers ) );``````
Learn it once, use it forever!
Highlighted

## Re: How do I create a custom transform function that takes multiple columns as inputs?

I copy/pasted that function out into a new JSL script and ran it, but the Log shows this error: "Cannot redefine a predefined JMP namespace"
Highlighted

## Re: How do I create a custom transform function that takes multiple columns as inputs?

OK, then replace the Here namespace with one of your own.

Learn it once, use it forever!
Highlighted

## Re: How do I create a custom transform function that takes multiple columns as inputs?

Sorry I'm so slow, I have no idea how to do that.
Highlighted

## Re: How do I create a custom transform function that takes multiple columns as inputs?

``````funcDef = Function( { number }, { i, sum },
If( Is List( number ),
Sqrt( Summation( i = 1, N Items( number ), number[i]^2 ) ),
.
);
);

description = "This function returns the root sum squared of a list numbers.";
parmHint = "a list of numbers";

/* create function using variables
the commands can also be accepted as arguments in New Custom Function */