You have placed the reference to the column in the Test table in the wrong place. Also, I changed from using a format to using Set Each Value. The end resulting calculation is the same, however the column is not a formula column. This results in having the new data table being independent from the Test table. I also changed the ending value for the For() loop. Since you are including 2 rows both before and after, you can not calculate beyond nrows-2
names default to here(1);
Test = Open( "$SAMPLE_DATA/blood pressure.jmp" ); //open value data table
Testcols = Test << Get Column Names( string, continuous ); //get column names
TestMA = New Table( "Test Table Smoothed" ); //make new table
TestMA << add rows( N Rows( Test ) ); //make new table match rows with raw table
For( i = 1, i <= N Cols( Test )-2, i++,
Eval(
Parse(
"TestMA << New Column( \!"MA_" || Testcols[i] ||
"\!",
numeric,
continuous,
set each value( Col Moving Average( test:" || Testcols[i] || ", 1, 2, 2 ) ) )"
)
);
);
TestMA << delete columns( "column 1" );
Finally, please use the JSL Icon at the top of the preview screen to enter your code. It makes for much easier reading.
The code actually does not require the complexity of the Eval(Parse()) code. It can just use open code
Names Default To Here( 1 );
Test = Open( "$SAMPLE_DATA/blood pressure.jmp" ); //open value data table
Testcols = Test << Get Column Names( string, continuous ); //get column names
TestMA = New Table( "Test Table Smoothed" ); //make new table
TestMA << add rows( N Rows( Test ) ); //make new table match rows with raw table
For( i = 1, i <= N Cols( Test ) - 2, i++,
TestMA << New Column( "MA_" || Testcols[i],
numeric,
continuous,
set each value( Col Moving Average( test:Testcols[i], 1, 2, 2 ) )
)
);
TestMA << delete columns( "column 1" );
Jim