DATA Step, Macro, Functions and more

Using "NOT IN" with macro code

Reply
N/A
Posts: 0

Using "NOT IN" with macro code

Hi all,
I was wondering is it possible to use "Not IN" in a conditional statement using the macro facility.

I have tried the code in a statement like this:
%IF &Variable NOT IN(Apples Oranges) %THEN %DO;
%IF (&Variable NOT IN Apples Oranges) % THEN %DO;
%IF (&Variable NOT IN (Apples Oranges)) %THEN %DO;

I have also tried quoting the variable and the list objects. Additionally, I have tried using commas as delimiters.

None of the above has run and all have given the error message in the log that "A character operand was found in the %EVAL function or %IF condition where a numeric operand is required."

Any help with this would be great!
Thanks

~Matt
Super Contributor
Super Contributor
Posts: 3,174

Re: Using "NOT IN" with macro code

Posted in reply to deleted_user
I would suggest using %SYSFUNC and the SAS INDEX function, given what you have shown for code.

Scott Barry
SBBWorks, Inc.
SAS Employee
Posts: 58

Re: Using "NOT IN" with macro code

Posted in reply to deleted_user
Yes, but to do this you first must set the minoperator option (which tells the SAS Macro Facility to recognize "in" as an operator). Then to use the "not" you need to put the original expression in parens and place the "not" outside. See below.

160 options minoperator;
161
162 %macro testit;
163 %if fred in fred %then
164 %put yes;
165 %else %put no;
166 %mend;
167
168 %macro testitagain;
169 %if not(fred in joe chuck al) %then
170 %put yes;
171 %else %put no;
172 %mend;
173
174 %testit;
yes
175
176 %testitagain;
yes
Super Contributor
Super Contributor
Posts: 3,174

Re: Using "NOT IN" with macro code

The option MINOPERATOR is new with SAS 9.2.

MINOPERATOR System Option
http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/a003092012.htm


Scott Barry
SBBWorks, Inc.
Ask a Question
Discussion stats
  • 3 replies
  • 2788 views
  • 0 likes
  • 3 in conversation