Hi there,
I am learning a macro program. I am confused about multiple operators. I don't know how SAS evaluates %if comparisons with two operators, one is "(&brand. = Flase)", the other is ">=.". the result of this program returned "Brand is General Electric". may I know why? how to decompose multiple operators?
.
%macro corpare_brand(brand);
%if ((&brand. = Flase) >=. ) %then %put Brand is General Electric;
%else %put Brand is &brand;
%mend;
%corpare_brand(Coke)
thanks!
SAS uses %EVAL() to evaluate the condition in a %IF statement.
So just ask %EVAL() what it thinks of those tests.
1009 %put %eval( Coke = Flase ); 0 1010 %put %eval(0 >= .); 1
the test:
%if ((&brand. = Flase) >=. ) %then
Is always TRUE.
Do you see why?
If you are just testing equality this works:
%macro corpare_brand(brand);
%if &brand. = Flase %then %put Brand is General Electric;
%else %put Brand is &brand;
%mend;
%corpare_brand(Coke);
the original macro program showed below:
%macro compare_brand(brand);
%if &brand = GE %then %put Brand is General Electric;
%else %put Brand is &brand;
%mend;
%compare_brand(Coke)
What are you trying to do with this -"%if ((&brand. = Flase) >=. )" ? Some sort of Boolean comparison?
SAS uses %EVAL() to evaluate the condition in a %IF statement.
So just ask %EVAL() what it thinks of those tests.
1009 %put %eval( Coke = Flase ); 0 1010 %put %eval(0 >= .); 1
the test:
%if ((&brand. = Flase) >=. ) %then
Is always TRUE.
Do you see why?
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.