turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- JMP User Community
- :
- Discussions
- :
- How to represent numeric value "1" as "001"?

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Feb 17, 2015 7:10 AM
(1085 views)

I have thousands of X and Y coordinates in two different columns and would like to combine the coordinates as 6-digit values into a single column. For example, combine (1,1) into 001001, and combine (14, 14) into 014014. A simplified data table is attached.

How do I do that using formula or script?

Bo

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Solution

Assuming X and Y never exceed three digits, this should work in a column formula:

Repeat( "0", 3 - Length( Char( :X ) ) ) || Char( :X ) ||

Repeat( "0", 3 - Length( Char( :Y ) ) ) || Char( :Y )

*Edit:*

Or maybe this is more efficient:

Right**(** Char**(** **1e6** + :X * **1e3** + :Y **)**, **6** **)**

5 REPLIES

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Assuming X and Y never exceed three digits, this should work in a column formula:

Repeat( "0", 3 - Length( Char( :X ) ) ) || Char( :X ) ||

Repeat( "0", 3 - Length( Char( :Y ) ) ) || Char( :Y )

*Edit:*

Or maybe this is more efficient:

Right**(** Char**(** **1e6** + :X * **1e3** + :Y **)**, **6** **)**

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Feb 17, 2015 9:34 AM
(868 views)

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Feb 17, 2015 7:44 AM
(868 views)

You can use the Repeat() function to pad out the character representation for these coordinates.

It would look like this:

**(**Repeat**(** "0", **3** - Length**(** Char**(** :X **)** **)** **)** || Char**(** :X **))** || **(**

Repeat**(** "0", **3** - Length**(** Char**(** :Y **)** **)** **)** || Char**(** :Y **))**

I've attached your data table with a new column showing this.

-Jeff

-Jeff

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Feb 17, 2015 9:35 AM
(868 views)

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Feb 17, 2015 10:32 AM
(868 views)

the left and right functions have a third argument to specify a pad value. JSL Character String Functions

x=42;

right( char(x), 3, "0");

"042"

be careful, some of the other suggestions may be more robust if the numbers are out-of-bounds, or maybe not, depending what you expect:

x=9876;

right( char(x), 3, "0");

"876"

Craige