BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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
5 REPLIES 5
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
I would suggest using %SYSFUNC and the SAS INDEX function, given what you have shown for code.

Scott Barry
SBBWorks, Inc.
PatrickG
SAS Employee
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
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.
himself
Quartz | Level 8

%IF (&Variable NOT IN (Apples Oranges)) %THEN %DO;

 

can try this, for you to use not in in macro , you have to use the %eval; but you can create a call symputx that will store the values apple and oranges , eg. lets say the macro variable with the name apple,oranges is fruits, so the macro &fruits will resolve to apple and oranges. so i will have the following code

also remember to put the options statement at the top of the macro;

 

options minioperator mindelimiter=","; 

 

like this

 %if not %eval (%upcase(&fruits) in APPLES,ORANGES) %then %do;

ChrisNZ
Tourmaline | Level 20

> I was wondering is it possible to use "Not IN" in a conditional statement using the macro facility.
Yes it is. Look at the minoperator and mindelimiter options.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 13611 views
  • 2 likes
  • 5 in conversation