You can use the Match() function to make several equality comparisons without needing to rewrite the value to be compared. The syntax is:
For Each Row( sex =
For each row in the table, sex is the column that is recoded.
|
|
Begins the Match() loop.
|
|
Specifies sex as the match argument.
|
|
This Match() example is a simplified version of the example in If. The advantage of Match() is that you define the comparison value once rather than repeat it in each condition. The disadvantage is that you cannot use expressions with operators as you can with If; the argument sex == "F" returns an error in a Match() expression.
With more groups of conditions and results, the value of Match() becomes more apparent. The following script would require many additional lines of code with If().
Booking Day of Week = Match( Booking Day of Week,
age = Match( age, 12, "Twelve", 13, "Thirteen", 14, "Fourteen", 15, "Fifteen", 16, "Sixteen", "Other" )
When data consists of integers such as 1, 2, and 3, you can save even more typing by using Choose(). See Choose for more information.
注意:The Match() function explicitly checks to see if the compare expression x is missing and if the value of value1 is missing, then it returns the value of result1; otherwise it continues to compare the expression x to each valueN value in each valueN/resultN pair, ignoring any missing values. If the expression x is equal to any of the valueN value, then the corresponding resultN value is returned. If no matching valueN value is found, then the resultElse value is returned.