Share your ideas for the JMP Scripting Unsession at Discovery Summit by September 17th. We hope to see you there!
Choose Language Hide Translation Bar
Highlighted
nqj
nqj
Level III

Using Pat Match within Loop

Hi,

I'm trying to write a program to take an input string, find a key word within the full string, and create a new column with just the abbreviation. The script should iterate over all the rows of a single column. My code throws an error and I believe it is the syntax of my loop but can't seem to figure out where the error is. Here is what I have:

 

For Each Row(
	:prodFam = If(
		Pat Match(:prodGroup, "aleutian"),
		"ALEUTIAN",
		Pat Match(:prodGroup, "ari"),
		"ARI",
		Pat Match(:prodGroup, "blue"),
		"BLUE RIDGE",

and the loop continues. Any help is greatly appreciated, thanks!

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

Re: Using Pat Match within Loop

You need a Boolean response for your If() function to work. That way is how the result of Contains() will be interpreted as I have already explained.

Learn it once, use it forever!

View solution in original post

5 REPLIES 5
nqj
nqj
Level III

Re: Using Pat Match within Loop

So I've realized that once you create a reference to a column, you no longer use colons to state that it is a column name. However, my script now runs without populating the table with the abbreviations. Am I still missing something? Thanks!

Highlighted

Re: Using Pat Match within Loop

First of all, if this code is not part of a larger script, then you could enter as a column formula. The argument in the For Each Row() function is the same as the column formula.

Second, while character string patterns are very useful, I I think that you could use Contains( test string, target string ) in this case.You are not looking for a pattern but a literal string (word). Contains() return the location if found or zero if not found. JMP interprets zero as false and non-zero as true, so your logic implemented with the If() functions stands as it is.

Learn it once, use it forever!
Highlighted
nqj
nqj
Level III

Re: Using Pat Match within Loop

the problem with using the Contains() function is that it returns a numeric value when I really just need a true or false boolean value. I suppose I could use the value it returns to index a substring, but in the end that seems like more lines of code for something that could be done using pat match, does it not? Thanks for the reply!

Highlighted

Re: Using Pat Match within Loop

You need a Boolean response for your If() function to work. That way is how the result of Contains() will be interpreted as I have already explained.

Learn it once, use it forever!

View solution in original post

Highlighted
David_Burnham
Super User

Re: Using Pat Match within Loop

As you say the Contains function returns a numeric value (the position where the item is contained). However, you can treat the value as boolean: 0=false, otherwise true, so you can write code that treats the Contains function as boolean:

 

If (Contains(...),

    // do something

)

-Dave
Article Labels

    There are no labels assigned to this post.