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?
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.