Choose Language Hide Translation Bar
Highlighted
Raybob
Level I

How to name window to include unique values from column, separated by _

I'm trying to rename a table so that it includes the unique names that appear in my column ("Product"). Sometimes I have one product, while other times I may have several products.

How would I script this? Below is what I have so far, which names the window with "-Data Table" and today's date.

dt1stacked << Set name( (ProductList, ",") || " -Data Table" || " " || Short Date( Today() ) );

 

 

 

Thanks!

2 REPLIES 2
Highlighted
txnelson
Super User

Re: How to name window to include unique values from column, separated by _

Here is a little function that will do what you asked for

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


setName = Function( {dt, colName},
	{defaultlocal},
	Summarize( dt, byGroup = by( As Column( dt, colName ) ) );

	theName = Column( dt, colName ) << get name;

	For( i = 1, i <= N Items( byGroup ), i++,
		theName = theName || "_" || byGroup[i]
	);

	Column( dt, colName ) << set name( theName );
);

setName( dt, "age" );
Jim
Highlighted
vince_faller
Super User

Re: How to name window to include unique values from column, separated by _

Assuming ProductList is from a summary or something.  Try

dt1stacked << Set name( ConcatItems(ProductList, ",") || " -Data Table" || " " || Short Date( Today() ) );
Vince Faller - Predictum