Wednesday, May 14, 2014

colon(:) operator modifier - Note 2

WHERE statement is so useful tool to subset data. However, colon(:) operator modifier can not be used in WHERE statement.
Currently I can find some workarounds at below:
1.
PROC SQL truncated string comparison operators such as EQT, GTT, and LET:
They are undocumented operators because I can not find them in SAS document. For more information, please read SUGI paper 056-2009.

Please note that they have to be used in WHERE statement of PROC SQL.
2.
LIKE operator:
WHERE name like 'J%'; * all name with leading J character;

3.
To encapsulate the operator in FCMP:
proc fcmp outlib=work.funcs.trial;
   function func_in(a $, b $);
      if a =: b then result=1;
      else result=0;

      return (result);
   endsub;
run;

options cmplib=work.funcs;

data test;
    set sashelp.class;
    if func_in(name, 'J');
run;

Although they can not really replace the colon(:) operator modifier, they are useful to open your mind.

No comments: