%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.
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.
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.