cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
The Discovery Summit 2025 Call for Content is open! Submit an abstract today to present at our premier analytics conference.
Choose Language Hide Translation Bar
View Original Published Thread

Custom function with varying number of input columns?

hogi
Level XII

Hi,

 

is it possible to define a custom function which works for 2-5 selected columns?

Add Custom Functions(
	New Custom Function(
		"custom",
		"concat",
		Function( {col1, col2, col3=., col4=., col5=.},
			If(not (is missing(col 4)),
			Char(col1) || "_" || Char(col2)|| "_" || Char(col3)|| "_" || Char(col4)|| "_" || Char(col5),
			not (is missing(col 4)),
			Char(col1) || "_" || Char(col2)|| "_" || Char(col3)|| "_" || Char(col4),
			not (is missing(col 3)),
			Char(col1) || "_" || Char(col2)|| "_" || Char(col3),
			not (is missing(col 4)),
			Char(col1) || "_" || Char(col2))
		),
		<<Transform Category( 1 ),
		<<Description( "combine 2-5 columns with underscore" ),
		<<Example(
			Expr(
				Show( custom:concat( :height, :weight, :sex, :age, :name ) );
			)
		)
	)
);
4 REPLIES 4
pmroz
Super User


Re: Custom function with varying number of input columns?

How about passing the columns in as a list?  That way there's only one argument, and it can have as many columns as you want.

hogi
Level XII


Re: Custom function with varying number of input columns?

I suffer from the missing concatenate entry in the right click / new formula column menu.
I want to create my own function. 
I guess the custom function can just be used for transforms if the columns are listed individually.

Jeff_Perkinson
Community Manager Community Manager


Re: Custom function with varying number of input columns?

Concatenate is there in JMP 18. 

2024-12-04_11-05-55.109.png

 

-Jeff
hogi
Level XII


Re: Custom function with varying number of input columns?

Unfortunately, NOT in general.

 

Yes, there is such a function.

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt << New Formula Column(
	Operation( Category( "Character" ), "Concatenate with Underscore" ),
	Columns( :height, :weight )
);


It appears in the right-click new formula column menu if at least one of the columns is a character column.

Unfortunately, the setting disappears if all columns are numeric  : (

Until now, we used a special shortcut icon in a toolbar.
A few days ago, one of my colleagues asked why there is no such possibility via the right-click new formula column.
So close - but for many cases: not accessible via the GUI.