Stacking two or more columns into one column

Originally taken from here the macro b_to_w.sps stacks a defined number of columns on top of one other (representing within subject level responses) to form one column which can serve as a between subject factor response.

The between subjects factor is also created in the column called numb. Note: you can also use th restructure command to do this.

DATA LIST FREE
        /idno b1 x b2 b3.
BEGIN DATA
1 3 4 7 1
1 6 5 8 2
1 3 4 7 3
1 3 3 6 8
2 1 2 5 10
2 2 3 6 10
2 2 4 5 9
2 2 3 6 11
END DATA.


define w_to_b (id=!tokens(1)
                      /nvars=!tokens(1)
                      /vars=!cmdend).

VECTOR b=!vars.
LOOP numb=1 TO !nvars.
COMPUTE newb=b(numb).
XSAVE OUTFILE 'C:\test2.sav'
   /KEEP !id numb newb.
END LOOP.
EXE.
GET FILE = 'C:\test2.sav'.
LIST.
!enddefine.

Let's give it a whirl:

w_to_b id=idno nvars=3 vars=b1 to b3.