BookmarkSubscribeRSS Feed
grsanford
Fluorite | Level 6

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;

2 REPLIES 2
PaigeMiller
Diamond | Level 26

Use the BY statement in PROC GLIMMIX and other data analysis PROCs

 

by depth year version;

  

--
Paige Miller
ballardw
Super User

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>)

 

 

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 118 views
  • 2 likes
  • 3 in conversation