Using Pat Match within LoopHi,
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!
Re: Using Pat Match within LoopAs 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
)
Re: Using Pat Match within LoopYou 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.
Re: Using Pat Match within Loopthe 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!
Re: Using Pat Match within LoopFirst 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.
Re: Using Pat Match within LoopSo 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!