You are calling the macro with just the letter P as the value, not the value of the macro variable P that you tested before you defined the macro and called. Add the value of the local macro variable P to your %PUT statements inside your macro definition so you can see what you actually tested.
The letter P is NOT less than the digit 0. Howver if you have told SAS to treat P when reading text into numbers as meaning special missing value .P by including it in the list of letters used in a MISSING statement then the test will find that P is < 0.05 since it will actually test if .P < 0.05 instead and all missing values are less than all actual numbers.
Thanks for all your inputs, without your helps, I couldn't figure it out. Here it the code to solve my problem.
Using %lsmeansOutput(&P) instead of %lsmeansOutput(P) in when calling this macro function after format P to FORMAT 12.5.
proc sql ; ** obtain p-value of trt;
select ProbF format 12.5 as P into :P
from Fixedp where Effect='Treatment';
run;
%macro lsmeansOutput(P);
%if %sysevalf(&P<.05) %then %do;
proc plm restore=&response.out;
lsmeans treatment/lines adjust=Tukey;
run;
%put Yes branch;
%end;
%else %do;
proc plm restore=&response.out;
lsmeans treatment;
run;
%put No branch;
%end;
%mend lsmeansOutput;
%lsmeansOutput(&P);
Your second example provides the expected result while being completely wrong 😉
You take the substring of a string with the length of 1 ("P"), starting at position 2; this results in an empty value, which is of course smaller than anything else.
To address a macro variable, you need the ampersand, period. There's only a handful of functions that deal with macro variables that expect the name without the ampersand (the SYMGET function, for example).
The last call
%lsmeansOutput(P)
cannot work.
You have passed the letter P to the macro. If you macro expected the NAME of a macro variable that might work, but even that could not work in this case since the global macro variable has the same name as the local macro variable (the parameters listed in the %macro statement are local macro variables). Inside the macro the local macro variables will hide any macro variables with the same name in any outer scope.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.