Subscribe Bookmark RSS Feed

JMP 13 Using Loc() with a list - changed behaviour?

stephen_pearson

Community Trekker

Joined:

Oct 6, 2014

I have just upgraded to JMP 13 and it has made many custom scripts stop working. I have traced the problem to a change in how lists handle the result from a loc query. The code below used to return "pear" in JMP 12 but now returns {"pear"}.

 

mylist = {"apple","pear"};
mychoice = "pear";

showchoice = mylist[loc(mylist, mychoice)];

I was using the list[loc()] syntax to create SQL comma separated strings to execute stored procedures.

 

The new behaviour is logical if unexpected. Regrettably Loc() still won't take a list argument as the look up value - that would have been a beneficial outcome. How would you recommend to get the desired result:

  • convert the Loc() result to a number?
  • replace showchoice with showchoice[1] in my code?
  • other?

I could convert my list of choice(s) to a string and strip out the { & } & \!". This will not always work as the text list I show the user is not always the same as the list from which the corresponding key is picked for the SQL request.

1 ACCEPTED SOLUTION

Accepted Solutions
markbailey

Staff

Joined:

Jun 23, 2011

Solution

I think that Loc() is supposed to take a matrix and return the location of true elements (non-zero).

Contains( list, item) works with lists and returns the location of the target item.

Learn it once, use it forever!
4 REPLIES
markbailey

Staff

Joined:

Jun 23, 2011

Solution

I think that Loc() is supposed to take a matrix and return the location of true elements (non-zero).

Contains( list, item) works with lists and returns the location of the target item.

Learn it once, use it forever!
stephen_pearson

Community Trekker

Joined:

Oct 6, 2014

Replacing Loc() with Contains() fixed the issue. Thanks. I guess I had been doing too much Matrix manipulation when I wrote this section of code.
David_Burnham

Super User

Joined:

Jul 13, 2011

This is abit like overfitting with predictive models. Your code is tuned to how JMP actually works as opposed to how it ought to work.  Which is fine, until the next release :-)

-Dave