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

UTF character data, encoding of text

Objective and Background :  You have text data that is UTF encoded and need SAS/R to read and write datasets with that encoding.  If you have ever printed or viewed text information, and seen something like Giuffr?Ÿ’e?ƒe?Ÿƒ?ÿ?›ƒ?ªƒ?›?Ÿ’e›ƒ?ª­?Ÿƒeee, then you are running into this encoding issue.  Computers store text using numbers, with each number assigned to a particular character.  See  https://en.wikipedia.org/wiki/ASCII  to find that the character & is stored as 38 when using the ASCII encoding.  Unicode is popular internationally because it encodes special characters such as accented letters, and UTF-8 is a widely used version ( https://en.wikipedia.org/wiki/UTF-8 ).  In UTF-8 the & character is stored as 26, and you can imagine how the jumbled example above arises from the confusion of what letters are being stored. Solution 1 :  Use options to request that individual datasets be read and written in a particular encoding.  In SAS, specify encoding options on the vario

Factorial ANOVA with control treatment not integrated into the factorial

Factorial treatment designs are popular, due to advantages of research on multiple treatment factors and how they interact.  But if the design includes a control treatment that is not part of the factorial, problems occur in estimation of least squares means.  A typical example is shown here, with 2 fertilizer and 3 irrigation treatments, giving 6 factorial treatment combinations, plus a control that is defined by a 3rd level of fertilizer, and a 4th level of irrigation: Fert1:Irrig2               Fert2:Irrig1             Fert1:Irrig1 Fert2:Irrig3               Fert1:Irrig3             Fert2:Irrig2           Control Other situations might have the control sharing a level of one of the factors, for example the control might be defined as Fert2:Irrig4.  But this still causes problems with estimation of least squares means due to the levels of one factor not occurring with all levels of the other factor. Let's jump into a SAS example, but using random numbers to allow easy creati