BookmarkSubscribeRSS Feed
ankitk321
Fluorite | Level 6

%if (%upcase(%trim("&Include_Exclude")) NE "INCLUDE") OR (%upcase(%trim("&Include_Exclude")) NE "EXCLUDE") OR (%upcase(%trim("&Include_Exclude")) NE "ALL DATASETS") %then %do;  

%message(Fatel Error:Values in Include/Exclude Dataset is not correct^20);

%goto exit;

%end;

 

value of Include_Exclude macro variable is "Include". I want if value is not equal to INCLUDE then exit macro. but it is not getting resolved and not giving correct result

 

I have tried following-:

1.Removing quotes from the macro variable and the value. for example --> (%upcase(%trim(&Include_Exclude)) NE  INCLUDE)

2. I have tried removing trim

 

But still not able to get the desired result.

 

Kindly help me to solve the same.

2 REPLIES 2
Astounding
PROC Star

Macro language does not require quotes to identify character strings.  Because you added them, %TRIM is doing nothing.  Best to get rid of them.

 

When you join three conditions using OR, one (or more) of the comparisons must be true.  The comparisons should use AND instead of OR:

 

%if %upcase(&Include_Exclude) NE INCLUDE

AND %upcase(&Include_Exclude) NE EXCLUDE

AND %upcase(&Include_Exclude) NE ALL DATASETS %then %do;  

 

If you are truly concerned about the value of &INCLUDE_EXCLUDE containing special characters or special words, switch from %UPCASE to %QUPCASE.

 

Amir
PROC Star

Hi,

 

If you are seeing a message in the log such as:

 

WARNING: Apparent symbolic INCLUDE_EXCLUDE reference not resolved.

 

then you might have a global vs local scope issue. If this is the case then try using the statement:

 

%global include_exclude;

 

before the variable is first used so that it can be accessed elsewhere.

 

If this is not the case then please share more of the log.

 

You might want to also consider changing the or conditions to and conditions as your test ends up being:

 

   "INCLUDE" ne "INCLUDE"

or "INCLUDE" ne "EXCLUDE"

or "INCLUDE" ne "ALL DATASETS"

 

which evaluates to:

 

   FALSE

or TRUE

or TRUE

 

which gives TRUE. Using and instead of or would give FALSE.

 

 

Regards,

Amir.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 2 replies
  • 583 views
  • 0 likes
  • 3 in conversation