- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Script to add leading characters (leading zeros in this case)
What's the syntax to have a column operate on itself?
This is the best I could come up with and it doesn't work.
dt = current data table();
column(dt, "Architecture") << Set Each Value( Repeat("0",3-Length(Char("Architecture")))||Char("Architecture"));
Column Architecture has values like 1, 2, 123, XXX, etc. Length is not standard.
Want a script that will run on the table and covert the column to standardize the length at 3 and add any leading zeros.
Resulting values would be, 001, 002, 123, XXX, etc.
Saw this post and it was almost there.
https://community.jmp.com/t5/Discussions/How-to-represent-numeric-value-quot-1-quot-as-quot-001-quot...
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Script to add leading characters (leading zeros in this case)
You need to loop through each row an apply the change:
Names Default To Here( 1 );
dt = Current Data Table();
For Each Row(
dt:Architecture = Repeat( "0", 3 - Length( Char( dt:Architecture ) ) ) ||
Char( dt:Architecture )
);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Script to add leading characters (leading zeros in this case)
You're almost there. Use the scoping character (single colon) to make sure JSL understands it's a variable (i.e. a column), and not a string.
dt = Current Data Table();
dt:Architecture << Set Each Value(Repeat("0", 3 - Length(dt:Architecture)) || dt:Architecture);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Script to add leading characters (leading zeros in this case)
JSL can forgive spaces in column names. But it can't forgive special characters. The following statements are equivalent references to a column.
dt:Architecture Digest
column(dt, "Architecture Digest")
For special characters you can use column() or :Name()
// Column with special characters, ABC=DEF?
column(dt, "ABC=DEF?")
:Name("ABC=DEF?")
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Script to add leading characters (leading zeros in this case)
You need to loop through each row an apply the change:
Names Default To Here( 1 );
dt = Current Data Table();
For Each Row(
dt:Architecture = Repeat( "0", 3 - Length( Char( dt:Architecture ) ) ) ||
Char( dt:Architecture )
);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Script to add leading characters (leading zeros in this case)
You're almost there. Use the scoping character (single colon) to make sure JSL understands it's a variable (i.e. a column), and not a string.
dt = Current Data Table();
dt:Architecture << Set Each Value(Repeat("0", 3 - Length(dt:Architecture)) || dt:Architecture);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Script to add leading characters (leading zeros in this case)
Thank you so much!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Script to add leading characters (leading zeros in this case)
JSL can forgive spaces in column names. But it can't forgive special characters. The following statements are equivalent references to a column.
dt:Architecture Digest
column(dt, "Architecture Digest")
For special characters you can use column() or :Name()
// Column with special characters, ABC=DEF?
column(dt, "ABC=DEF?")
:Name("ABC=DEF?")
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Script to add leading characters (leading zeros in this case)
Thank you both. The software is great and the user community is even better!