Friday, November 20, 2015

IN operator

It is my favorite operator. Generally it is used to compare one expression on the left of the operator to a list of values on the right. However, you may find the two tricks are helpful.
#1. To search some variables, we have to use array.
data _null_;
    a=11;
    b=2;
    c=3;
    array vars a b c;
    /* if 1 in (a, b, c) then put "OK"; ERROR: we can not search the list of variables directly. */
    if 1 in vars then put "OK";
run;

#2. The modifier ":" can work well with IN operator.
data _null_;
    a='11';
    b='2';
    c='3';
    array vars a b c;
    if '1' in: vars then put "OK";
    if '111' in: vars then put "OK";
run;

No comments: