BookmarkSubscribeRSS Feed
Rohan_Garg4
Calcite | Level 5

Hi everyone I have a specific question regarding my anova I have created. I have to create 4 anova results, and when I run my code it creates anovaresults2, anovaresults3 and anovaresults4, I do not know why my anovaresults 1 does not show up as I have set each anova up the same way. My code is below please let me know what you think is going wrong, THANK YOU!

 

ODS OUTPUT ModelANOVA = WORK.ModelResults1;
PROC ANOVA 
DATA = MIInq.MIIInquiry2;
CLASS StateCd;
Model AgeAtVisit = StateCd;
RUN;
 
%MACRO RunANOVA (Number = , Variable = );
ODS OUTPUT ModelANOVA = MIOut.ANOVAResults&Number;
PROC ANOVA
DATA = MIInq.MIInquiry2;
CLASS StateCd;
MODEL &Variable = StateCd;
RUN;
QUIT;
 
 
PROC PRINT DATA = MIOut.ANOVAResults&Number;
RUN;
 
%MEND RunANOVA;
 
%RunANOVA (Number = 1, Variable = AgeAtVisit)
%RunANOVA (Number = 2, Variable = SBP)
%RunANOVA (Number = 3, Variable = DBP)
%RunANOVA (Number = 4, Variable = WtLb);
 
PROC MEANS DATA = MIInq.MIInquiry2;
CLASS StateCd;
VAR WtLb;
RUN;
 
DATA MIOut.ANOVAResults (KEEP = Dependent FValue ProbF);
SET WORK.ANOVAResults: ;
RUN;

 

4 REPLIES 4
PaigeMiller
Diamond | Level 26

Please read the log from this code and see if there are ERROR or WARNING or NOTE that explains this.

 

If that doesn't get you the answer, then please add

options mprint;

as the first line of your program, run the whole thing, and then you look at the log, with the extra information and see if an ERROR or WARNING or NOTE indicates what the problem is.

 

As a last resort, if none of the above seems to indicate the problem, show us the log by performing the following steps:

 

  1. Copy the log as text. We need the entire log for this section of code, with nothing chopped out
  2. Include the log into your reply by clicking on the </> icon and then pasting the log into this window. DO NOT SKIP THIS STEP. This preserves the formatting and makes the log much more readable. I no longer even try to read logs posted that don't follow this step.
--
Paige Miller
WarrenKuhfeld
Ammonite | Level 13

https://documentation.sas.com/?docsetId=statug&docsetTarget=statug_ods_examples06.htm&docsetVersion=...

 

As a matter of general principles, always put the ODS OUTPUT statements after the PROC statements.

Reeza
Super User

FYI - if you search on here you'll find a method I suggested that accomplishes everything you're trying to do WITHOUT macros and significantly less code. One of your classmates already asked this question.

 

As to why it's not running, as others have indicated you'll need to provide the log - it usually has the errors and reasons why. If it works for one set of variables and not another it's likely something specific with that piece of code or variable, that we can't answer without the data. You can also try it with a known data set that's similar such as sashelp.heart.

 


@Rohan_Garg4 wrote:

Hi everyone I have a specific question regarding my anova I have created. I have to create 4 anova results, and when I run my code it creates anovaresults2, anovaresults3 and anovaresults4, I do not know why my anovaresults 1 does not show up as I have set each anova up the same way. My code is below please let me know what you think is going wrong, THANK YOU!

 

ODS OUTPUT ModelANOVA = WORK.ModelResults1;
PROC ANOVA 
DATA = MIInq.MIIInquiry2;
CLASS StateCd;
Model AgeAtVisit = StateCd;
RUN;
 
%MACRO RunANOVA (Number = , Variable = );
ODS OUTPUT ModelANOVA = MIOut.ANOVAResults&Number;
PROC ANOVA
DATA = MIInq.MIInquiry2;
CLASS StateCd;
MODEL &Variable = StateCd;
RUN;
QUIT;
 
 
PROC PRINT DATA = MIOut.ANOVAResults&Number;
RUN;
 
%MEND RunANOVA;
 
%RunANOVA (Number = 1, Variable = AgeAtVisit)
%RunANOVA (Number = 2, Variable = SBP)
%RunANOVA (Number = 3, Variable = DBP)
%RunANOVA (Number = 4, Variable = WtLb);
 
PROC MEANS DATA = MIInq.MIInquiry2;
CLASS StateCd;
VAR WtLb;
RUN;
 
DATA MIOut.ANOVAResults (KEEP = Dependent FValue ProbF);
SET WORK.ANOVAResults: ;
RUN;

 


 

 

PaigeMiller
Diamond | Level 26

Yep, @Reeza is correct, you don't need macros here at all, which probably simplifies the code greatly. https://communities.sas.com/t5/SAS-Programming/Using-Macro-Variables-With-Proc-Anova/m-p/703459#M215...

--
Paige Miller

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 4 replies
  • 1136 views
  • 0 likes
  • 4 in conversation