Depending on exactly what is required, an alternative approach may be to manipulate the row states directly:
NamesDefaultToHere(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
// List of 'by' variables
byCols = {:age, :sex};
// Loop over 'by' variables
for(c=1, c<=NItems(byCols), c++,
// What are the levels of this variable
levs = AssociativeArray(byCols[c]) << getKeys;
// Loop over levels
for(i=1, i<=NItems(levs), i++,
// Start with a clean slate
dt << clearRowStates;
// Template expression to select rows appropriately
CMD = Expr(dt << selectWhere(byCol != lev));
// 'Bake in' the current values
SubstituteInto(CMD, Expr(byCol), byCols[c], Expr(lev), Eval(levs[i]));
// Finally make the selection
CMD;
// Hide and exclude
dt << Hide << Exclude;
// Make graphs . . .
Wait(1);
);
);
dt << clearRowStates;
If it's Graph Builder specific, you could also take advantage of the fact that it will actually consume a 'by' variable when you launch it.