Hi All,

I am trying to capture an error when a user does not correctly specify an option requiring a "<", ">", "lt", or "gt". Each one of these options must be followed by a space, so that "<" and ">" must have a length of 2 (including space) while "lt" and "gt" must have length of 3 (including space).

The following code incorporates two !inlist() functions, which gives an error regardless of whether the option "direction" is correctly specified or not. Any help would be greatly appreciated!

Ariel

Code:
local direction lt 1223

di substr("`direction'",1,3)

if !inlist(substr("`direction'", 1, 2), "< ", "> ") | !inlist(substr("`direction'", 1, 3), "lt ", "gt ") {
di as err " direction must start with one of the following: <, >, lt, gt, followed by a space"
exit 198
}