Referring to Contiguous Columns in JSLHi,
I often have to delete a number of contiguous columns in datasets I work with. I've searched through the documentation and can't find the answer to referring to a series of contiguous columns in JSL. For example, I might use the following code to delete a set of columns:
Current Data Table()<< delete columns(QA_1,QA_2,QA_3,QA_4,QA_5,QA_6,QA_7,QA_8,QA_9,QA_10);
The list can get long and cumbersome and they aren't always in any kind of numeric order as above. I'd like a way to do the following (except this doesn't work):
Current Data Table()<< delete columns(QA_1 to QA_10);
What do I use for the "to" in the above line? Thanks very much.
Re: Referring to Contiguous Columns in JSLThanks, I'll try it out and let you know!Re: Referring to Contiguous Columns in JSLThat function will accept a list but I don't think it will do what you want so directly. Possibly grouping them and deleting the group will work but that's a few steps too. This script seems to work. You could turn it into a function. Run it as is, and it will stop at the stop() command. Then run the code after the stop command after the file is loaded to see the before / after. To do this you can just highlight the code after the stop() and hit ctrl+r or run.
Names Default To Here( 1 );
dt = open( "$SAMPLE_DATA\Big Class.jmp");
firstCol = "age";
lastCol = "height";
firstColNum = -1;
lastColNum = -1;
for(i = 1, i <= ncol(dt), i++,
if(column(dt, i)<<GET name="">= firstColNum,
for(i = lastColNum, i >= firstColNum, i--,
dt << delete columns(i)
)
);</GET>