Share your ideas for the JMP Scripting Unsession at Discovery Summit by September 17th. We hope to see you there!
Choose Language Hide Translation Bar
Highlighted

Referencing a selected column in a new column formula

I am constantly needing to convert Date:Time columns (M/D/Y hh:mm:ss) to date columns and am looking for a script I can add in as a tool such that I can select the Date:Time column I am wanting to use (regardless of the name of the column) to make a new date column and have the script saved into an easy to access shortcut. 

 

The part I am not able to figure out is how I can reference a "selected column" in the new column formula... I feel it should be along the lines of what I have below, except in the formula I am not currently able to figure out how to reference the selected column. 


dt1 = Current Data Table();

sc1 = dt1 << Get Selected Columns;

dt1<<new column("Date", Numeric, set each value("SC1" - time of day("SC1")));

 

In my current data table the Date:Time column is named DviStartTime and is in the format (m/d/y hh:mm:ss), I want to add a new column named date without having to specify the exact name of the column. 

 

Any help is appreciated!


Jocelyn

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
txnelson
Super User

Re: Referencing a selected column in a new column formula

You need to use the As Column() function, or in some cases the Column() function to be able to reference the columns with memory variables.  See below:

dt1 = Current Data Table();
sc1 = dt1 << Get Selected Columns;

dt1<<new column("Date", Numeric, set each value(as column(dt1, sc1)- time of day(as column(dt1,sc1))));
Jim

View solution in original post

2 REPLIES 2
Highlighted
txnelson
Super User

Re: Referencing a selected column in a new column formula

You need to use the As Column() function, or in some cases the Column() function to be able to reference the columns with memory variables.  See below:

dt1 = Current Data Table();
sc1 = dt1 << Get Selected Columns;

dt1<<new column("Date", Numeric, set each value(as column(dt1, sc1)- time of day(as column(dt1,sc1))));
Jim

View solution in original post

Highlighted

Re: Referencing a selected column in a new column formula

Perfect thank you!

Article Labels

    There are no labels assigned to this post.