BookmarkSubscribeRSS Feed

Use the “by” statement to split treatments for twin analyses

Started ‎05-21-2020 by
Modified ‎05-21-2020 by
Views 2,079

You can split your data set on the fly. Use a by statement to split treatments and conduct parallel analyses.

 

What happens when a violation of test assumptions derails your analysis plan? You can quickly split treatments into two analysis using the “by” statement in  mixed model procedures.

 

We uploaded the dataset from a study on heath plants tested the effect of plant source, drought and nitrogen.  Researchers performed the experiment twice in a greenhouse over two years. A previous data review showed different results by year.

 

Suppose you want to quickly evaluate each experimental repeat (year) independently and simultaneously. We do this by inserting a “by” statement into the statistical test procedure.

 

*** Start by sorting the data;
proc sort data=Heath.data;
by Year Heathland Nitrogen Drought Replicate;
*** this “by” modifies the proc sort statement. Below, we will use by to modify the ANOVA procedure;
run;
ods html close;
run;
ods graphics on;
proc mixed data=Heath.data Plots(only)=(studentpanel(conditional) Boxplot(conditional));
by 'Year'n;
***The sort by year creates one analysis output for each year.;
class Year Heathland Nitrogen Drought Replicate;
model 'dry weight above (g)'n= Drought|Nitrogen|Heathland;
random 'Year'n;
RUN;
 

by blog output 2010.png

2010 residual plots

 

by blog output 2011.png

2011 residual plots

  

And voila, your analysis is split by year! Notice the residual variance no longer violates our normality assumption.


If we were interested in only one year’s data, we could use the “Like” conditional statement.


While most of us find frustration in model assumption violations, segmenting observations does not have to be. The 'by' statement is one way to split treatments and execute parallel tests when the full factor model falls short.

Version history
Last update:
‎05-21-2020 09:36 AM
Updated by:
Contributors

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Free course: Data Literacy Essentials

Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning  and boost your career prospects.

Get Started

Article Tags