BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Tom
Super User Tom
Super User

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.

 

RosieSAS
Obsidian | Level 7

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);

 

Kurt_Bremser
Super User

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.

RosieSAS
Obsidian | Level 7
Your inference makes sense, but when p>0.05, it did run the %else condition without grouping results. I don't know how that happened. Do you mean &y should be used instead of y for every macro function %function(y)?
Kurt_Bremser
Super User

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).

Tom
Super User Tom
Super User

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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 21 replies
  • 2499 views
  • 10 likes
  • 5 in conversation