You will have to collect the results into a list / matrix / some other data structure inside the loop and then handle saving that OUTSIDE the loop.
You could also first create the file as empty (or in the first cycle of the loop) with replace mode (default mode) and then append new data to the file using replace mode Save Text File(path, text|BLOB, <Mode("Replace"|"Append")>) .
Most likely you would want to add headers to the .csv file and the column name.
Names Default To Here(1);
filepath = "$TEMP/test.csv";
dt = Open("$SAMPLE_DATA/Big Class.jmp");
colnames = {"height", "weight"}; // many method of getting these
For Each({colname}, colnames,
fm = dt << Fit Model(
Y(Eval(colname)),
Effects(:age, :sex),
Personality(Standard Least Squares),
Emphasis(Minimal Report),
Run
);
pvals = fm << Get Effect PValues;
// list conversion seems to be necessary for for JSON conversion
// and it is easiest to do here
fm << close window;
If(!File Exists(filepath),
savemode = "replace";
,
savemode = "append"
);
Save Text File(filepath, Char(pvals) || "\!N", mode(savemode));
wait(0); // most likely unnecessary
);
// Web(filepath);
If I were to do something like this, I would most likely collect the results into JMP table, clean it if needed and save into desired format
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
colnames = {"height", "weight"}; // many method of getting these
dt_result = Empty();
For Each({colname}, colnames,
fm = dt << Fit Model(
Y(Eval(colname)),
Effects(:age, :sex),
Personality(Standard Least Squares),
Emphasis(Minimal Report),
Run
);
dt_p = Report(fm)[Outline Box("Effect Tests"), Table Box(1)] << Make Combined Data Table(Invisible);
fm << close window;
dt_p << Delete Scripts(dt_p << Get Table Script Names);
If(Is Empty(dt_result),
dt_result = dt_p;
dt_result << Set Name("pvalues");
,
dt_result << Concatenate(Append to first table, dt_p);
Close(dt_p, no save);
);
);
dt_result << show window(1);
You could then save this into a .csv using (or save it as JMP table to make sure you don't lose any data in decimals)
dt_result << Save("$TEMP/test.csv");
-Jarmo