Someone in the SAS Communities forum asked this. They wanted to write a script that created a Graph Builder report without knowing in advance how many variables there would be. That is, they wouldn't how many variables there were when they were writing the script, but the script would know how many at run-time.
The original attempt contained a Graph Builder script inside a loop over the columns, but it was launching Graph Builder n times, once for each loop iteration. Instead, you need to somehow construct a single script which accounts for the variable number of columns and then run that script. JSL supports that kind of meta-programming (a script that creates another script) using the functions Expr(), Name Expr() and Eval Expr(). These are pretty advanced functions but also pretty powerful.
Then we make a note the parts we want to parameterize -- in this case the Y variables, and use a script to create that part based on run-time information and then glue it into the overall expression.
There are ways to get the same effect. A similar but often easier-to-understand technique is to construct the script as a text string and then call Parse() and Eval() on it when you're done. Another way: Graph Builder also supports messages like Add Variable which can modify an already-constructed Graph Builder report.