1) if x in (1, 3, 4) is a valid syntax
2) if x in (x1, x2, x3) is a invalid
which means one has to write
3) if x=x1 or x=x2 or x=x3.
I suggest syntax 2) should be valid.
It does if the variables are elements of an array.
The syntax is
expression in array-name
Thanks data_null_, but I am talking about the in operator accepting variable names.
And I am proposing that this be valid in sas code
Other syntaxes may be valid for other cases, but that is irrelevant.
x1=whichc('watermelon', of fruit
x2=('watermelon' in fruit); is also valid
But this is not related to my OP, which is about the in operator accepting variable names.
It doesn't. I suggest it should.
Seems like "make work" for developers and they could use that time to give us something we really need.
I believe arrays are generally underutilized as variable lists.
Unfortunately, using arrays for this purpose is a rather limited workaround:
1- arrays are only valid in a data step.
2- arrays cannot be used in a where clause.
The in operator on the other hand can be used with almost all procedures as part of a where clause.
So, the overlap between my suggestion and the array workaround is tiny, and as a replacement this workaround is poor indeed.
Furthermore, once variables names are recognised by the parser, expressions can (hopefully right away, or as a further enhancement) be used too, as in:
x1 in (2, var3/100).
This proposal is analogous to the SPSS ANY operator, which was about the only thing I found in SPSS I really liked.
SAS would be easier to use if everywhere it accepted a number or text constant it would also accept any expression. If that is not possible, at least give us variables. Make the language simpler and more consistent. Remove as many special cases as possible.
I still like this idea. I've always found my self wanting this to work at one time or the other. If anything comes of this perhaps a function like:
which equals true only when y equals any of the parameters x1 through xn.
Doesn't the IN() function already support this? They just need to document it.
if IN(x,x1, x2, x3) THEN ...
Well, there you go!
BUT... Reeza just introduced me to WhichC() and WhichN(), which can do this AND is documented.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.