*/////////////////////.

DEFINE !Rand_Group (Groups !TOKENS (1) / NewVar !TOKENS (1))

Match files file=* / DROP !NewVar.

Compute Rand=RV.UNIFORM(0,1).

SORT CASES BY Rand (A).

compute row=$casenum.

RANK VARIABLES=row (A) /NTILES (!Groups) into !NewVar /PRINT=YES /TIES=HIGH.

Match files file=* /drop row Rand.

VARIABLE LEVEL !NewVar (Nominal).

Var label !NewVar "Random Group".

Val labels !NewVar 1'One' 2'Two' 3'Three' 4'Four' 5'Five' 6'Six' 7'Seven' 8'Eight' 9'Nine' 10'Ten'.

Freq !NewVar.

!ENDDEFINE.

*/////////////////////.

!Rand_Group Groups=10 NewVar=Rand_GP.

If you want to first sort them on a variable the below macro will handle that for you.

*/////SPSS macro 2////////////////.

DEFINE !Group (Sorter !TOKENS (1) / Groups !TOKENS (1) / NewVar !TOKENS (1))

Match files file=* / DROP !NewVar.

SORT CASES BY !Sorter (A).

compute row=$casenum.

RANK VARIABLES=row (A) /NTILES (!Groups) into !NewVar /PRINT=YES /TIES=HIGH .

Match files file=* /drop row.

VARIABLE LEVEL !NewVar ( ORDINAL ).

Var label !NewVar "Group".

Val labels !NewVar 1'One' 2'Two' 3'Three' 4'Four' 5'Five' 6'Six' 7'Seven' 8'Eight' 9'Nine' 10'Ten'.

Freq !NewVar.

!ENDDEFINE.

*/////////////////////.

!Group Sorter=numords Groups=10 NewVar=Dec_Frequency.