Hello SAS Communities,
I am working with the following Proc Anova which is testing whether the means of a continuous variable are continuous across 3 different states. My code for this Anova is listed here:
ODS OUTPUT ANOVAResults = WORK.Results;
PROC ANOVA
DATA= WORK.Analysis
ORDER = INTERNAL;
CLASS State;
MODEL AgeAtVisit = State;
RUN;
QUIT;
Based on the above code, I am wanting to create a macro definition named 'RunANOVA' and specify 2 macro variables named 'Value' and 'Name'. The macro variable 'Value' will be used to create unique data sets containing the results by appending a number to the word 'Results' to create unique temporary data sets (i.e. Results 1, etc.) which will then be combined into one final data set. The macro variable 'Name' should specify the variable to be analysed in the Model statement.
My question: how do I modify the original Proc Anova to include the 'Number' and 'Variable' macro variables?
Thank you,
James
%macro runanova(number,varname);
ODS OUTPUT ANOVAResults = WORK.ANOVAResults&number;
PROC ANOVA
DATA= HypAnl.HypAnalysis2
ORDER = INTERNAL;
CLASS StateCd;
MODEL &varname = StateCd;
RUN;
QUIT;
%mend runanova;
%runanova(1,ageatvisit)
%runanova(2,sbp)
Or maybe an improvement — so that instead of relatively meaningless numbers to identify the data set, the actual name of the variable used goes into the data set name to help you identify the data set.
%macro runanova(varname);
ODS OUTPUT ANOVAResults = WORK.ANOVAResults_&varname;
PROC ANOVA
DATA= HypAnl.HypAnalysis2
ORDER = INTERNAL;
CLASS StateCd;
MODEL &varname = StateCd;
RUN;
QUIT;
%mend runanova;
%runanova(ageatvisit)
%runanova(sbp)
You don't need a macro, you can put multiple tables into the MODEL statement and get the results. If you have values missing for variables, this will not give you the same results most likely as there is rowwise deletion for observations with missing values.
Also, I don't see a table name called AnovaResuts so I think that part of your code is incorrect, I think it should be OverallAnova instead.
ODS OUTPUT OverallAnova = ANOVAResults; proc anova data=sashelp.heart; class bp_status chol_status; model ageatDeath weight = bp_status chol_status; run; quit;
Your results will have a variable that indicates which results go with which variable as well, which is slightly easier to work with IMO.
@JamesPatton01 wrote:
Hello SAS Communities,
I am working with the following Proc Anova which is testing whether the means of a continuous variable (AgeAtVisit) are continuous across 3 different states (StateCd). My code for this Anova is listed here:
ODS OUTPUT ANOVAResults = WORK.ANOVAResults;
PROC ANOVA
DATA= HypAnl.HypAnalysis2
ORDER = INTERNAL;
CLASS StateCd;
MODEL AgeAtVisit = StateCd;
RUN;
QUIT;
Based on the above code, I am wanting to create a macro definition named 'RunANOVA' and specify 2 macro variables named 'Number' and 'Variable'. The macro variable 'Number' will be used to create unique data sets containing the results by appending a number to the word 'AnovaResults' to create unique temporary data sets (i.e. AnovaResults 1, etc.) which will then be combined into one final data set. The macro variable 'Variable' should specify the variable to be analysed in the Model statement. The variables that I am working with are: AgeAtVisit, SBP, DBP, and WtLb.
My question: how do I modify the original Proc Anova to include the 'Number' and 'Variable' macro variables?
Thank you,
James
I like @Reeza's method better than my own. One data set as output containing all the results is usually preferable to multiple data sets. And easier to code (avoids un-needed macros). And quicker to run. And SAS provides more rebates to the user when you do it this way (I just made that part up)
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: