cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Choose Language Hide Translation Bar
xeqapena
Level I

set data type for new column

Hi, How can I conditionally and programmatically set a data type for a new column? I have a workaround that covers numeric / character, and it could be extended for other types, but I'm trying to get the method below (marked 'not working') to work. The log shows it is not recognizing the type variable. I've tried a few things like parse() but have been so far unsuccessful.

Names Default To Here( 1 );

dt = open( "$SAMPLE_DATA\Big Class.jmp");

colType = column(dtData,"Name") << get data type;

// doesn't work, error on colType
dt << add multiple columns("New Column", 1, After("Name"), colType);

// works
dt << add multiple columns("New Column", 1, After("Name"), Numeric);
if(colType == "Character", column(dt, "New Column") << data type ("Character"));
 

 

 

2 REPLIES 2
txnelson
Super User

Re: set data type for new column

The Add Multiple Columns does not appear to allow for parsing before the actual execution of the statement.  Therefore, what is presented as the Add Multiple Columns needs to be fully fleshed out before giving it to JMP for execution.  Here are a couple of ways to do that

Names Default To Here( 1 );
dt = Current Data Table();
coltype = "character";
Eval(
	Parse(
		Eval Insert(
			"dt << add multiple columns(\!"New Column\!", 1, After(\!"Name\!"), ^colType^)"
		)
	)
);

// or

Eval(
	Substitute(
			Expr(
				dt << add multiple columns(
					"New Column",
					1,
					After( "Name" ),
					__type__
				)
			),
		Expr( __type__ ), colType));
	
Jim
ih
Super User (Alumni) ih
Super User (Alumni)

Re: set data type for new column

Jim nailed it; here are a few more ways to construct that statement in case any one resonates better with your code:

 

Insert one expression into another using Eval Insert, Eval Expr, Parse, and Substitute