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?
Has that functionality been released yet? I tried
ReplyDelete%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
Interesting, I hadn't tried %IN.
ReplyDeleteIt 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.
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.
ReplyDeletehttp://support.sas.com/kb/11/945.html
Wow! Good researching Laurent. I knew something was going on, I just didn't have time to look all around.
ReplyDeleteI 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!
it seems odd that SAS would remove this, even if only temporarily...
ReplyDeletehere'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);
Thanx for the help! Carpenter's complete guide to the SAS Macro Language was wrong!
ReplyDeleteUnder SAS 9.2 both in and # work if you add the systemoption minoperator:
ReplyDeleteExamples:
%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;
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
ReplyDelete%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