BookmarkSubscribeRSS Feed
Reader587
Calcite | Level 5

Hey Everyone,

I am trying to create a macro variable where I perform a One-Way ANOVA. If the pvalue for the test of equal variance is less than 0.05 then do a welch anova.  Note: I have not included the "else" part of the statement as yet. 

Here is my code:

 

%macro group3(dsn,class,outcome);
%let largestpvalue=;
%if &largestpvalue le 0.05 %then %do;
%let i=1;
%let alloutcome=%scan(&outcome,&i);
%let myoutcome=;
%do %until (&alloutcome eq );
%put &largestpvalue;
%let myoutcome=&myoutcome &alloutcome;
title "&alloutcome.";
proc glm data=&dsn;
class &class;
model &alloutcome=&class;
ods output HovFTest=&alloutcome.;
means &class/hovtest=levene(type=abs) welch;
lsmeans &class;
run;
proc sql;
select round(max(probF),.0001) as largestpvalue
into:largestpvalue
from &alloutcome.;
quit;title;
%let i=%eval(&i+1);
%let alloutcome=%scan(&outcome,&i);
%put &myoutcome;
%end;%end;
%mend group3;
%group3(sashelp.iris,species,Sepallength sepalwidth Petallength petalwidth);

4 REPLIES 4
ballardw
Super User

What are you asking for help  with?

 

Reader587
Calcite | Level 5

I am asking for help with getting the correct result. The code is not giving me what I want. I want to do Welch ANOVA only when the pvalue is less than 0.05 (The pvalue for the test of equal variance). 

ballardw
Super User

How will we recognize a "correct result"?

We don't have your result.

 

"The code is not giving me what I want." is not a very clear description of what you do want.

Pvalue less than 0.05 for which exact test? The code you are showing appears to be attempting to run multiple ANOVA with different result variables. So I am not sure which specific Pvalue you are intending.

 

I suggest that you set OPTIONS MPRINT; and then run your macro and read the log as to the generated statements.

I strongly suspect that you have a timing issue of where in your code you compare the "largestpvalue" to when it is assigned.

Also there can be some issues with comparisons to values like 0.05 if you do not take care to use something like %sysevalf to make sure that a decimal comparison is performed and not a text comparison.

 

Post code into a text box or code box, opened with the </> and "running man" icons respectively to maintain code indents and such. Your code is a bit hard to follow without them and the forum software will reformat text not pasted into one of those boxes.

 

As an aside when "looping" over a list I find an explicit loop like:

%do i = 1 %to %sysfunc(countw(&list));

   %let value = %scan(&list,&i);

 

a bit easier to follow and get the timing correct than a %do %until loop as you show for the "outcomes".

 

Quentin
Super User

If you code:

%if &largestpvalue le 0.05 %then %do;

the macro language will use call %EVAL() to evaluate the expression, and because %EVAL does not know about decimal points it will do a text comparison.  Since you want to do a numeric comparison, one improvement would be to explicitly call %SYSEVALF:

%if %sysevalf(&largestpvalue le 0.05) %then %do;

But there may be other issues as well.

 

BASUG is hosting free webinars Next up: Mark Keintz presenting History Carried Forward, Future Carried Back: Mixing Time Series of Differing Frequencies on May 8. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 406 views
  • 0 likes
  • 3 in conversation