Hi @WernerL ,
Below is some code to do that (writing either values, or column formulas), but might I ask, why do you need to create a table like this? If you need to perform some operations row-wise with a value in a previous row from a previous column, there are more efficient ways than explicitly creating those lag columns.
This form writes values:
dt = Open("$SAMPLE_DATA\Big Class.jmp");
baseCol = Column("height");
nCopies = 6;
For( i = 1, i <= nCopies, i++,
spacerMat = J( i, 1, . );
valuesMat = spacerMat |/ Eval( baseCol << Get Values );
New Column( "Copy " || char(i), Numeric, "Continuous", Set Values( valuesMat ) );
);
This form writes column formulas:
dt = Open("$SAMPLE_DATA\Big Class.jmp");
baseCol = Column("height");
nCopies = 6;
For( i = 1, i <= nCopies, i++,
Eval(Substitute( Expr( New Column( "Copy " || Char( i ), Numeric, "Continuous", Formula( Lag( Subscript(xxCol,row()), i ) ) ) ), Expr( i ), i, expr(xxCol), baseCol ))
);
I hope this helps get you started!
@julian
//Edit 11/24/19: made a correction to the column formula version to correctly substitute the column defined at the start of the script into the column formula