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;
%test;


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

8 comments:

  1. Has that functionality been released yet? I tried

    %macro test;
    %if 1 %in (3 4 1 5) %then %put it works;
    %mend test;
    %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

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

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

    http://support.sas.com/kb/11/945.html

    ReplyDelete
  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!

    ReplyDelete
  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);
    %end;
    %put &match;
    %mend;

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

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

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

    Examples:

    %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;
    %test;

    ReplyDelete
  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

    %MACRO ENTRE(UND,CONJ);
    %LET NOBS = %EVAL(%SYSFUNC(COUNTC(&CONJ,' '))+1);
    %LET SAL=0;
    %DO I=1 %TO &NOBS;
    %LET M=%EVAL(&UND EQ %SCAN(&CONJ,&I));
    %LET SAL=%EVAL(&SAL + &M);
    %END;
    %PUT &SAL;
    %RETURN;
    %MEND ENTRE;

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

    ReplyDelete