ANY function in SAS

I have been using SAS for a few months now and am starting to think in SAS code. There are still times when I get frustrated mainly because my internal function library isn’t complete.  Sometimes I’m sure SAS is missing a function I’m used to using elsewhere.  Luckily this isn’t a big problem – you just write a SAS macro to fill the void!

So this was my ANY function: %ANY(variable, condition1, contion2, …)
resolves to: variable=condition1 OR variable=contion2…

%macro ANY/parmbuff;
   %let var=%scan(&syspbuff,1);
   %let num=2;
   %let val=%scan(&syspbuff,&num);
   %let s = &var=&val;
   %do %while(&val ne);
      %let s = &s or &var=&val;
      %let num=%eval(&num+1);
      %let val=%scan(&syspbuff,&num);
   %end;
   &s;
%mend ANY;

Used as:

%PUT %ANY(id,321,2321);
PROC PRINT DATA=sashelp.class;
   WHERE %ANY(name,'Barbara','John');
RUN;

However, as with most things SAS, there is a super easy way to do this – you just need to know it! Meet the IN operator:

PROC PRINT DATA=sashelp.class;
   WHERE name in ('Barbara','John');
RUN;

I only noticed that this is what the clever SAS log complies to (NOTE: it is listed in the help under ‘IN operator’)…  Anyway, problem solved and  I will now never forget the IN.