Hi,
I think that your problem is that N Cols (dt) increases after each iteration of your loop. Therefore, your index value "i" exceeds the number of elements in your collist list.
I suggest capturing the number of columns in dt outside the loop and using it as a fixed limit.
path = "my file path with filename.jmp";
dt= open(path);
collist = dt <<get column names(string);
colname = Column("test1") <<getname;
colnumber = (Loc(collist,colname))[1];
num_col = N Cols (dt);
For(i=colnumber+1, i<=num_col,i++,
dt <<new column("SG_"||collist[i], character);
);
Of note, I am unsure why the reverse loop works. You it should run into a similar issue with your collist variable.
Let us know if that solve your issue.
Best,
TS
Thierry R. Sornasse