An Idea Exchange for SAS software and services

by Respected Advisor
on ‎06-05-2013 07:24 AM

It does if the variables are elements of an array.

The syntax is

expression in array-name

by PROC Star
on ‎06-05-2013 08:07 AM

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

  • );   is valid
  • 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.

    by Respected Advisor
    on ‎06-06-2013 09:14 AM

    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.

    by PROC Star
    on ‎06-09-2013 10:34 PM

    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).

    by Super User
    on ‎05-14-2014 02:56 PM

    This proposal is analogous to the SPSS ANY operator, which was about the only thing I found in SPSS I really liked.

    by Contributor Peter_L
    on ‎06-05-2014 06:55 AM

    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.

    by Regular Contributor
    on ‎06-17-2016 03:45 PM

    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



    by Super User
    on ‎06-19-2016 12:07 PM

    Doesn't the IN() function already support this?  They just need to document it.

    if IN(x,x1, x2, x3) THEN ...
    by Regular Contributor
    on ‎06-20-2016 09:13 AM

    Well, there you go! 

    by Regular Contributor
    on ‎06-20-2016 10:39 AM

    BUT...  just introduced me to WhichC() and WhichN(), which can do this AND is documented. 

    Idea Statuses
    Top Liked Authors