cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Don’t miss your chance to experience Discovery Summit Europe at our best available rate! Early bird registration through 31 Oct.
  • Graph Builder Toolbar streamlines interactive graphing. Creates shortcuts on Report and GraphBuilder Helpers toolbars. Download and install the extension.
  • JMP will suspend normal business operations for our Rest and Recharge Day on Friday, October 2, 2026.
    Regular business hours will resume on Monday, October 5, 2026.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
Shadow
Level II

Using "Left" on a string

Hi,

I think this should be easy but have spent too much time trying to figure it out. I have a more complex worksheet with a longer list (that refers to column names that may change) but what I am trying to do is create a new list to be used else where by removing the word "_Yield" from my original list. Simple example below;

 

<JSL>

Names Default To Here( 1 );
exurl = {"Test_Yield, Help_Yield"};
X = Left(exurl, Contains( exurl, "_Yield" ) - 1 );

 

For this I want to get X = {"Test", "Help"} but I just get X = exurl

 

1 ACCEPTED SOLUTION

Accepted Solutions
SDF1
Super User

Re: Using "Left" on a string

Hi @Shadow ,

 

  Along with what @JohnDMoore1 suggested for the substitute, which is a great way to do it, another option can be the following:

Names Default to Here(1);

exurl = {"Test_Yield", "Help_Yield"};

x={};
For(i=1, i<=NItems(exurl), i++,
	x[i]=left(exurl[i], Contains(exurl[i], "_Yield")-1);
);

  I think one of the things that's throwing the Left command off is that it is a multi-element list -- even though the scripting index says it can deal with lists, it doesn't appear to actually have that ability. The For loop helps to build your output variable as a list. Sometimes this kind of approach is more flexible, especially when you have large data tables and need to rename many columns, etc.

 

  Also, I think there is a mistake in your example url that you gave. You wrote: exurl={"Test_Yield, Help_Yield"}, which is only a single string, not a list. I think what you meant to write is exurl={"Test_Yield", "Help_Yield"} which has the extra quotes and comma separating the elements in the list.

 

Hope this helps!,

DS

View solution in original post

4 REPLIES 4
JohnDMoore1
Level II

Re: Using "Left" on a string

I tend to use substitute in these situations

 

X = substitute(exurl,"_Yield","");
Shadow
Level II

Re: Using "Left" on a string

Hi John, Thanks for your reply. I had tried that but still get X = excurl. 

SDF1
Super User

Re: Using "Left" on a string

Hi @Shadow ,

 

  Along with what @JohnDMoore1 suggested for the substitute, which is a great way to do it, another option can be the following:

Names Default to Here(1);

exurl = {"Test_Yield", "Help_Yield"};

x={};
For(i=1, i<=NItems(exurl), i++,
	x[i]=left(exurl[i], Contains(exurl[i], "_Yield")-1);
);

  I think one of the things that's throwing the Left command off is that it is a multi-element list -- even though the scripting index says it can deal with lists, it doesn't appear to actually have that ability. The For loop helps to build your output variable as a list. Sometimes this kind of approach is more flexible, especially when you have large data tables and need to rename many columns, etc.

 

  Also, I think there is a mistake in your example url that you gave. You wrote: exurl={"Test_Yield, Help_Yield"}, which is only a single string, not a list. I think what you meant to write is exurl={"Test_Yield", "Help_Yield"} which has the extra quotes and comma separating the elements in the list.

 

Hope this helps!,

DS

jthi
Super User

Re: Using "Left" on a string

If you have access to JMP16+, this is a good place to use Transform Each

Names Default To Here(1);
exurl = {"Test_Yield", "Help_Yield"};
X = Transform Each({url}, exurl, Substitute(url, "_Yield", ""));
show(X); // X = {"Test", "Help"};

 

-Jarmo

Recommended Articles