cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
bernie426
Level II

JSL character type time convert to numeric nominal

I have a Character Col that all input value is in time, like hh:mm:ss (like 05:36:50), I would like to convert it to numeric, nominal type with a format of h:m.

The script I wrote for this request is listed below, but it does not work out as expected, can anyone give it a modify?

dt<<Current Data Table();

dt<< New Column("Time_Set",Numeric, Nominal, Format("h:m"));

dt<< Being data update;

  For each row(:Time_Set=Num(":Time Added:"));

  dt<< Move Selected Columns ({"Time_Set"},After("Time Added:"));

1 ACCEPTED SOLUTION

Accepted Solutions
pmroz
Super User

Re: JSL character type time convert to numeric nominal

The trailing colon in your column name is what threw me.  This code will work:

dt = Current Data Table();

dt << New Column("Time_Set",Numeric, Nominal, Format("h:m"));

for (i = 1, i <= nrows(dt), i++,

     :time_set[i] = informat(:name("Time Added:")[i], "h:m:s");

);

View solution in original post

7 REPLIES 7
pmroz
Super User

Re: JSL character type time convert to numeric nominal

dt = Current Data Table();

dt << New Column("Time_Set",Numeric, Nominal, Format("h:m"));

for (i = 1, i <= nrows(dt), i++,

     :time_set[i] = informat(:Time Added[i], "h:m:s");

);

bernie426
Level II

Re: JSL character type time convert to numeric nominal

Hi PMroz,

I tried the script you wrote, but it did not work out. A Time_Set is created under numeric nominal type, but the entire column is blank.

Thanks,

pmroz
Super User

Re: JSL character type time convert to numeric nominal

Can you post a portion of your data?  Perhaps your character time column is not quite in the right format, e.g. leading/trailing spaces etc.

bernie426
Level II

Re: JSL character type time convert to numeric nominal

Hi PMorz,

The uploaded file is the sample file. Thanks for your help!

please let me know if you cannot open it.

pmroz
Super User

Re: JSL character type time convert to numeric nominal

The trailing colon in your column name is what threw me.  This code will work:

dt = Current Data Table();

dt << New Column("Time_Set",Numeric, Nominal, Format("h:m"));

for (i = 1, i <= nrows(dt), i++,

     :time_set[i] = informat(:name("Time Added:")[i], "h:m:s");

);

bernie426
Level II

Re: JSL character type time convert to numeric nominal

Thanks, PMorz....

Jeff_Perkinson
Community Manager Community Manager

Re: JSL character type time convert to numeric nominal

A quick note on the Informat() function – it doesn't require a second argument. If you leave it off, JMP will try all the formats it knows to interpret the first argument as a date/time value.


-Jeff

-Jeff