Subscribe Bookmark RSS Feed

JSL character type time convert to numeric nominal

bernie426

Community Trekker

Joined:

Feb 9, 2015

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
Solution

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");

);

7 REPLIES
pmroz

Super User

Joined:

Jun 23, 2011

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

Community Trekker

Joined:

Feb 9, 2015

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

Joined:

Jun 23, 2011

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

Community Trekker

Joined:

Feb 9, 2015

Hi PMorz,

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

please let me know if you cannot open it.

Solution

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

Community Trekker

Joined:

Feb 9, 2015

Thanks, PMorz....

Jeff_Perkinson

Community Manager

Joined:

Jun 23, 2011

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