Split current data file in n random groups
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | Option Explicit Sub Main ' This script splits the data file into n (random) groups' ' Where n is supplied by the user ' Posted to SPSSX-L list on 2004/03/23 by Raynald Levesque Dim strCmd As String Dim vNbPieces As Variant Dim lngNumCases As Long lngNumCases = objSpssApp.Documents.GetDataDoc(0).GetNumberOfCases If lngNumCases = 0 Then MsgBox ("You need to load data in Data Editor " & vbCrLf & "before running this script!",vbCritical) Exit Sub End If Do vNbPieces =InputBox("Split file in how many random pieces?", "Input # of pieces",2) If vNbPieces = "" Then Exit Sub Loop Until IsNumeric(vNbPieces) strCmd = strCmd & "COMPUTE draw=UNIFORM(1)." & vbCrLf strCmd = strCmd & "SORT CASES BY draw." & vbCrLf strCmd = strCmd & "COMPUTE groupnb=MOD($CASENUM," & vNbPieces & ")." & vbCrLf strCmd = strCmd & "EXECUTE." & vbCrLf strCmd = strCmd & "" & vbCrLf objSpssApp.ExecuteCommands (strCmd,False) End Sub |
Related pages
...