cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Instantly extract effect sizes, F-ratios, and FDR-adjusted p-values from your models with the Calculate Effects Sizes extension, available now in the JMP Marketplace!
  • New to JMP? Join us Sept. 23-24 for the Early User Edition of Discovery Summit, tailor-made for new users. Register now for free!
  • Your voice matters! Tell us how you prefer to receive JMP updates, so we can tailor our communication to your needs. Take short survey.

Discussions

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

Indexing into a list without errors

Let's say I have a file name that I parse into separate parts like so:

nameWords = Words(name, "_")

Let's say I want to make a short name out of the first five words of the original name:

shortName = Concat Items( nameWords[{1, 2, 3, 4, 5}], "_" );

Everything works fine while I'm getting names in the format that I expect, i.e. more than five words in the name.

But as soon as I get name like "aaa_bbb_ccc" (quite unexpected, but totally real) I get an error when indexing into my list.

Question: How do I index into not 5, but the least of 5 and the N Items of the list? Rather than write an IF statement to figure out which is less?

2 ACCEPTED SOLUTIONS

Accepted Solutions
miguello
Level VII

Re: Indexing into a list without errors

There you go:

shortName = Concat Items(nameWords[1::Min(NItems(nameWords), 5)])

View solution in original post

jthi
Super User

Re: Indexing into a list without errors

You could also use Left()

Names Default To Here(1);

a = "1_2_3_4_5_6_7_8";
b = "1_2_3";

Show(Concat Items(Left(Words(a, "_"), 5), "_"));
Show(Concat Items(Left(Words(b, "_"), 5), "_"));

 

 

-Jarmo

View solution in original post

2 REPLIES 2
miguello
Level VII

Re: Indexing into a list without errors

There you go:

shortName = Concat Items(nameWords[1::Min(NItems(nameWords), 5)])
jthi
Super User

Re: Indexing into a list without errors

You could also use Left()

Names Default To Here(1);

a = "1_2_3_4_5_6_7_8";
b = "1_2_3";

Show(Concat Items(Left(Words(a, "_"), 5), "_"));
Show(Concat Items(Left(Words(b, "_"), 5), "_"));

 

 

-Jarmo

Recommended Articles