cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Sign-in to the JMP Community will be unavailable intermittently Dec. 6-7 due to a system update. Thank you for your understanding!
  • We’re retiring the File Exchange at the end of this year. The JMP Marketplace is now your destination for add-ins and extensions.
  • JMP 19 is here! Learn more about the new features.

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