What I'm trying to do is to compare means after treatment p<0.05. First I saved p value through PROC SQL, then according to the p value to decide if needing to group the means or not. However, when p<.0001, the macro function %lsmeansOutput(P) always runs without LINES option as p>=0.05. When there is an exact p value<0.05, for example p=0.025, the macro function works correctly to show the mean grouping results.
Is there anyone can help me figure out the reason?
proc sql ; ** obtain p-value of trt;
select ProbF as intP into :intP
from Fixedp where Effect='Treatment';
run;
%macro lsmeansOutput (P);
%if &P<0.05 %then %do;
proc plm restore=&response.out;
ods exclude diffplot meanplot classlevels;
lsmeans treatment/lines;
run;
%end;
%else %do;
proc plm restore=&response.out;
ods exclude diffplot meanplot classlevels;
lsmeans treatment;
run;
%end;
%mend lsmeansOutput;
I also posted the problem in Programming forum, but not sure where is more appropriate, programming problem or statistical analysis problem. Thanks in advance!
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);
Macro language does not treat decimal points as numeric. You would need to change this line:
%if &P<0.05 %then %do;
Instead, code it as:
%if %sysevalf(&P<0.05) %then %do;
You need to show exactly how you are calling your macro LsmeansOutput. As in the code.
Since P is a parameter passed to the macro how it is passed is important.
And since you are using the same name for the data set &Response.out are you actually using a different data set? Not showing where macro values come from is a common problem with debugging macros.
One of the common tools is to set Options Mprint Mlogic Symbolgen; before running the macro to see the code generated, macro logic (the %if ) resolution and the values of macro variables as built, such as &Response.out.
You have the proc sql code that creates a variable called intP, but the code below references macro variable P. There is no value set in macro variable P. Is it your intention to pass the value from proc sql to the next step below?
To start troubleshooting your macro, you do want to turn on the SAS options mentioned by another user. You can also use put statements to write messages to the log. I suspect that you are passing P<.0001 as a character value which then never meets this condition. The top argument in the sample code below is a brute force workaround adding P<.0001 as a possible if-then condition.
%macro lsmeansOutput(p);
%if %sysevalf(&p = <.0001) %then %do;
%put p=&p;
%end;
%else %if %sysevalf(&p<0.05) %then %do;
%put p=&p;
%end;
%else %do;
%put met else condition=&p;
%end;
%mend;
%lsmeansOutput(p=.01);
%lsmeansOutput(p=.05);
%lsmeansOutput(p=.0001);
%lsmeansOutput(p=<.0001);
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);
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.
Find more tutorials on the SAS Users YouTube channel.