cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Learn how to build custom Python data connectors and further customize JMP’s Data Connector Framework with the Python Data Connector Demo, available now in the JMP Marketplace!
  • See how to create experiments to support product design and ID useful product features. Register for June 12 webinar, 2pm US Eastern Time.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
Phil_Nash
Level II

Recode a value in a column with a formula instead of a static value

The original value that is in the table that I want to recode will always be 01/01/1900.  I want to recode that to today's date.  This only returns a blank, and not today's date.  Any idea what I need to change?

 

Thanks!

 

Transfers << Begin Data Update;
Transfers << Recode Column(
	Transfers:OrderDate,
	{Map Value( _rcOrig, {-126144000, short date(today())}, Unmatched( _rcNow ) )},
	Update Properties( 1 ),
	Target Column( :OrderDate )
);
Transfers << End Data Update;
2 REPLIES 2

Re: Recode a value in a column with a formula instead of a static value

I am not sure that the source column and the destination column can be the same data column. Here is the example from the scripting index:

 

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
col = New Column( :age );
col << Data Type( "Character" );
dt << Recode Column(
	:age,
	{If(
		_rcNow >= 17, "Older",
		_rcNow >= 15, "Middle",
		"Younger"
	)},
	Target Column( col )
);
hogi
Level XIII

Re: Recode a value in a column with a formula instead of a static value

To recode entries in a column and save the result to the same column, one can select In Place from the drop down menu:

hogi_0-1759868337446.png

In the JSL code the target column will match the input column.

Hm, Why does the code not work? 

a) Short Date() converts the date to a String - but the column is numeric.

b) even after removing short date() it doesn't work. Because  Map value() doesn't allow expressions? maybe:

hogi_1-1759868519259.png

 

So let's try:

Transfers = New Table( "transfers",
	Add Rows( 1 ),
	Compress File When Saved( 1 ),
	New Column( "OrderDate",
		Format( "y/m/d"),
		Set Values( [-126144000] )
	)
);

Transfers << Begin Data Update;
Eval (Eval Expr(Transfers << Recode Column(
	Transfers:OrderDate,
	{Map Value( _rcOrig, {-126144000, Expr(today())}, Unmatched( _rcNow ) )},
	Update Properties( 1 ),
	Target Column( :OrderDate )
)));
Transfers << End Data Update;

  

Recommended Articles