I would like to save a number of variables to a file with sequential variables names, for example x1, x2, x3, etc. Is there a way to abstract this, and put it in a loop so that I do not have to type:
save x1; save x2; save x3;
1 Answer
0
Here is a procedure that will accomplish your task:
proc (0) = saveSeqVars(varname, nvars); local outname, tmp, i; for i(1, nvars, 1); outname = varname$+ftos(i, "%*.*lf", 0, 0); tmp = varget(outname); save ^outname=tmp; endfor; endp;
Using this function, the call:
saveSeqVars("myvar", 3);
would be equivalent to:
save myvar1; save myvar2; save myvar3;
Your Answer
1 Answer
0
Here is a procedure that will accomplish your task:
proc (0) = saveSeqVars(varname, nvars); local outname, tmp, i; for i(1, nvars, 1); outname = varname$+ftos(i, "%*.*lf", 0, 0); tmp = varget(outname); save ^outname=tmp; endfor; endp;
Using this function, the call:
saveSeqVars("myvar", 3);
would be equivalent to:
save myvar1; save myvar2; save myvar3;