Skip to main content

DANDA - A macro collection for easier SAS statistical analysis

Objective:  You are running ANOVAs or regressions in SAS, and wish there was a way to avoid writing the dozens of commands needed to conduct the analysis and generate recommended diagnostics and summary of results, not to mention the hundreds of possible options that might be needed to access recommended methods.  A possible solution is to download a copy of danda.sas below, and use this macro collection to run the dozens of commands with one statement.  We will also have future posts covering various uses of danda.sas, giving examples as always.

danda.sas is under continued development, check this page for updates.
Date                       Version            Link
2021/03/15             2.12.030         danda.sas
2021/03/15             2.12                UserManual.pdf  
2012/08/30             2.11                danda211.sas

Example:  You have an RBD split-plot design, so typical SAS code for mixed model ANOVA is
proc mixed data=one;
  class block treat week;
  model height = treat | week / outp=rrr;
  random block  block*treat;
  lsmeans treat | week /pdiff;
run;
proc univariate plot normal data=rrr;
  var resid;
run;
proc means data=rrr;
  class treat week;
  var resid;
run;

and on and on to get other results.  Note that the above code has errors, illustrating how easily researchers may overlook recommended options, such as ddfm=kr to request the popular Kenward-Roger degrees of freedom adjustment, needed for models with multiple error terms such as this example.  Least squares means differences will be printed as a huge table, very difficult to condense into the typical ABC letter grouping indicating which means differ.  And if you have multiple y-variables, you have to repeat all this code for each y-variable, as Proc Mixed only allows one dependent variable.  If you needed to switch to Proc Glimmix, then option names change as well as some of the commands, resulting in more potential coding mistakes.  To be fair, SAS has made improvements recently with ODS graphics incorporated into all procs, potentially making the procs following Proc Mixed unnecessary.

In comparison, the above analysis could be run by
%include 'd:\myfolder\danda.sas';
%mixedaov(one, yvar1 yvar2 aaa--zzz, class=block treat week, fixed=treat|week, random=block block*treat);
That is it!  The user only needs to specify the elements of the model, and list all dependent variables.  The macro implements the standard recommended options and diagnostic checks (eg. normality) automatically.  The %include makes the macros available, with the user specifying where on the computer the danda.sas file is saved.

Comments

Popular posts from this blog

Reporting results from transformed analyses

Objective :  Transformed data, for example log(y), is analyzed to correct normality or equal variance requirements.  But we want to report means and standard errors in the original units. SAS example : data one;  do treat=1 to 3;  do rep=1 to 5;    y=10 + treat+ exp(rannor(111));    logy=log(y);    output;  end;end; run; proc mixed plots=all;   class treat;   model y=treat;   lsmeans treat/pdiff; run; proc mixed plots=all;   class treat;   model logy=treat;   lsmeans treat/pdiff; run; The original data, variable y, might have units of pounds.  If a transformation is needed, we simply calculate a new variable by applying a mathematical function known to improve normality or equal variance, and run the same analysis on the new variable.  Commonly used choices are listed in the second table below. However, looking at the results for both analyses we see treat Mean Y S...

Estimation of the Peak in Quadratic Regression

 Problem:   You are running a standard quadratic (polynomial) regression analysis, and are specifically interested in the X and Y values at the peak.  If you use standard regression software, typically there will be no option that allows the peak to be estimated, with standard errors. Example:   You are studying Growth as a function of Age.  Of particular interest is when maximum Growth occurs, and at what Age. SAS code to generate artificial data, and run the analysis is: data one; do Age=1 to 20; Growth=95 + 2.7*Age - .3*Age*Age + 5*rannor(22); end; proc nlin plots=fit; parms int=2 lin=1 quad=1; model Growth = int + lin*Age + quad*Age*Age; estimate 'Age at peak' -lin/(2*quad); estimate 'Growth at peak' int + lin*(-lin/(2*quad)) + quad*(-lin/(2*quad))*(-lin/(2*quad)); run; The standard quadratic regression model with intercept, linear and quadratic slopes, is coded into Proc NLIN which has the ability to estimate any fun...