Google SAS Search

Add to Google

Tuesday, January 29, 2008

New Macro IN Operator

Has anyone gotten the new IN Macro operator to work? I just want to test it out and SAS Macro keeps coughing up an error that a character operand is found where a numeric operand is required.

According to the documentation, you can use the # character or the mnenomic IN. Their example is A#B C D E.

I am trying to test it with:

%macro test;
%if A#B C D E A %then %put it works;
%mend test;

Pretty straightforward as far as I can tell. Am I overlooking something obvious?


  1. Has that functionality been released yet? I tried

    %macro test;
    %if 1 %in (3 4 1 5) %then %put it works;
    %mend test;

    and got the following message '%IN will become a reserved keyword of the SAS Macro Language in a future release of the SAS System.'

    I am using SAS 9.1.3 for Linux

  2. Interesting, I hadn't tried %IN.

    It is straight out of "What's New In the SAS 9 and 9.1 Macro Language Facility". So I would assume they wouldn't document it as new if they hadn't released it yet.

  3. I got the same error. After searching the SAS site I found a note explaining that is has been disabled in 9.1.2 and 9.1.3, but it will return in 9.2.

  4. Wow! Good researching Laurent. I knew something was going on, I just didn't have time to look all around.

    I took a quick look at your web site, and though I can't read it, I noticed you have a link Last.FM which makes you a winner in my book!

    Thanks again!

  5. it seems odd that SAS would remove this, even if only temporarily...

    here's a quick macro that might do what you want:
    %macro in(needle,haystack);
    %let n = %sysfunc(countw(&haystack));
    %let match = 0;
    %do i = 1 %to &n;
    %let m = %eval(&needle eq %scan(&haystack, &i));
    %let match = %eval(&match + &m);
    %put &match;

    %in(a,a b c);
    %in(z,a b c);

  6. Thanx for the help! Carpenter's complete guide to the SAS Macro Language was wrong!

  7. Under SAS 9.2 both in and # work if you add the systemoption minoperator:


    %macro test / minoperator; %if A#B C D E A %then %put it works;%mend test;%test;

    %macro test /minoperator;
    %if 1 in (3 4 1 5) %then %put it works;
    %mend test;

  8. Thx guys for the info, and RichardK your code not work in SAS 9.0 the function countw need 2 or more arguments my versión is

    %LET SAL=0;
    %DO I=1 %TO &NOBS;
    %LET SAL=%EVAL(&SAL + &M);
    %PUT &SAL;

    I find that the function FINDC may be usefull to replace IN operator