- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
How do I conditionally set data type for new column in JSL?
Hi, How can I conditionally and programmatically set a data type for a new column? I have a workaround that covers numeric / character, and it could be extended for other types, but I'm trying to get the method below (marked 'not working') to work. The log shows it is not recognizing the type variable. I've tried a few things like parse() but have been so far unsuccessful.
Names Default To Here( 1 );
dt = open( "$SAMPLE_DATA\Big Class.jmp");
colType = column(dtData,"Name") << get data type;
// doesn't work, error on colType
dt << add multiple columns("New Column", 1, After("Name"), colType);
// works
dt << add multiple columns("New Column", 1, After("Name"), Numeric);
if(colType == "Character", column(dt, "New Column") << data type ("Character"));
Thanks,
Mike
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: How do I conditionally set data type for new column in JSL?
This will do the trick for you
Eval(
Substitute(
Expr(
dt << add multiple columns( "New Column", 1, After( "Name" ), __coltype__ )
),
Expr( __colType__ ), Parse( coltype )
)
)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: How do I conditionally set data type for new column in JSL?
Thank you for reporting this issue. The original post revealed a defect within JSL. A few clever solutions were offered, which were great workarounds. I can report now that in JMP 14, the original code (marked "doesn't work" in the example script) now works correctly and as expected.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: How do I conditionally set data type for new column in JSL?
This will do the trick for you
Eval(
Substitute(
Expr(
dt << add multiple columns( "New Column", 1, After( "Name" ), __coltype__ )
),
Expr( __colType__ ), Parse( coltype )
)
)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: How do I conditionally set data type for new column in JSL?
Thanks Jim. That works well. The eval(substitute(expr(...))) has always confused me as to when to use it because it seems an overcomplicated way of getting the variable where it needs to go. Is it fair to say that it is always needed if I'm trying to put a variable into such an expression?
Thanks,
Mike
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: How do I conditionally set data type for new column in JSL?
You are correct. This is typically the best way to populate expressions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: How do I conditionally set data type for new column in JSL?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: How do I conditionally set data type for new column in JSL?
Thank you for reporting this issue. The original post revealed a defect within JSL. A few clever solutions were offered, which were great workarounds. I can report now that in JMP 14, the original code (marked "doesn't work" in the example script) now works correctly and as expected.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: How do I conditionally set data type for new column in JSL?
Thanks!