BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
cruss1
Calcite | Level 5

I am using a %if statement inside a macro to execute code when &var does NOT match eye or hand. But the code inside the %if is still submitting when it gets to var = eye. How can I write this so that body = &var + 1; does NOT happen when var equals hand or eye?

 

 

 

data x;

set y;

%macro look (var);

%if &var ne hand or &var ne eye %then %do;

body = &var + 1;

%end;

%mend look;

%look (hand);

%look (eye);

%look (arm);

run;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

It looks like a logic error.  Your %IF condition must always be true.  Change "or" to "and".

View solution in original post

3 REPLIES 3
Astounding
PROC Star

It looks like a logic error.  Your %IF condition must always be true.  Change "or" to "and".

nehalsanghvi
Pyrite | Level 9

You need an 'and', not an 'or' in this statement:

 

%if &var ne hand and &var ne eye %then %do;

nehalsanghvi
Pyrite | Level 9

The way you have it currently written with an 'or', any one of the two conditions needs to be true for the statement inside to execute. When you pass in hand, &var ne eye is true, so it executes. When you pass in eye, &var ne hand is true so it executes. What you intend to say is execute code only if both conditions are true - not hand AND not eye.

 

%if &var ne hand and &var ne eye %then %do;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 3 replies
  • 757 views
  • 0 likes
  • 3 in conversation