I am wondeirng what the most efficient way to cycle through several data subsets or response variables in a statistical procedure such as proc glimmix (or similar). I have always relied on creating new data sets (e.g. data new; set data old;), or using the where statments (where 'this' and 'that' are met). Both still require copying and pasting the same model multiple times which seems like something a true programer would scoff at me about (see below). I would LOVE some suggestions to make my code more succinct and parsimonious. Thank you!
proc glimmix data=SOC plots=studentpanel; where depth = "0_15" and year=2009 and version = "new";
nloptions maxiter=500;
class year block system depth plot subplot version;
model deltaSOC_Mg_ha = system / ddfm=kr;
random block;
random _residual_ / subject=plot group=system type=arh(1);
run;
proc glimmix data=SOC plots=studentpanel; where depth = "15_30" and year=2009 and version = "new";
nloptions maxiter=500;
class year block system depth plot subplot version;
model deltaSOC_Mg_ha = system / ddfm=kr;
random block;
random _residual_ / subject=plot group=system type=arh(1);
run;
Use the BY statement in PROC GLIMMIX and other data analysis PROCs
by depth year version;
To expand on @PaigeMiller 's response with your example code: The following sort and BY statement will run ALL the combinations of depth, year and version in sort order. If you want all of the same versions together in output then use a sort order in both By statements with the Version first, or the year though that may not be critical.
Proc sort data=SOC; by depth year version; run; proc glimmix data=SOC plots=studentpanel; by depth year version; nloptions maxiter=500; class year block system depth plot subplot version; model deltaSOC_Mg_ha = system / ddfm=kr; random block; random _residual_ / subject=plot group=system type=arh(1); run;
Also note that the values of the By variables can be addressed in Title statements and even used in some ODS destinations to control some output aspects.
If you don't want all the combinations then you still sort and use the BY statement but modify the WHERE clause to use IN with value lists. For example (assuming some likely values for example).
where depth in ("0_15" "15_30") and year in (2008 2009 2010) and version in ("new" "proposed");
Or if you want to exclude some of a long list of values: variable NOT IN (<list>)
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 16. Read more here about why you should contribute and what is in it for you!
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.