该帮助的版本不再更新,请参见https://www.jmp.com/support/help/zh-cn/15.2 获取最新的版本.


You can use the Match() function to make several equality comparisons without needing to rewrite the value to be compared. The syntax is:
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
Match(
"F", "Female",
"M", "Male",
"Unknown");
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().
dt = Open( "$SAMPLE_DATA/Travel Costs.jmp" );
Booking Day of Week = Match( Booking Day of Week,
"Sunday", "SUN",
"Monday", "MON",
"Tuesday", "TUE",
"Wednesday", "WED",
"Thursday", "THU",
"Friday", "FRI",
"Saturday", "SAT",
"Not Specified"
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
age = Match( age, 12, "Twelve", 13, "Thirteen", 14, "Fourteen", 15, "Fifteen", 16, "Sixteen", "Other" )
注意: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.