' Demo: this script combines all sav files (meeting a given mask eg *.sav) located in a given folder ' The sav files will normally have the same variables (but it works even if they don't) ' The label of the variable source contains the path of the data files ' The value labels of the variable source contain the name of the source data files ' rlevesque@videotron.ca 2001/10/2 ' Visit my SPSS site http://pages.infinit.net/rlevesqu/index.htm Option Explicit Sub Main Dim strPath As String Dim strFilemask As String ' Modify the next 2 lines to fit your requirements strPath ="c:\\temp\\" strFileMask ="f*.sav" Call CombineDataFiles(strPath, strFileMask) End Sub Sub CombineDataFiles (strPath As String, strFileMask As String) Dim strFname As String Dim strCmd As String Dim intFileNb If InStr(strPath, "\\") = 0 Then 'no path given, use current folder strPath = objSpssApp.GetSPSSPath End If If Len(strFileMask) = 0 Then 'no file Mask given, combine all files strFileMask = "*.sav" End If 'Get the first file name and load file strFname = Dir$(strPath & strFileMask) strCmd = "GET FILE='" & strPath & strFname & "'." & vbCr strCmd = strCmd & "COMPUTE source=1." & vbCr strCmd = strCmd & "VALUE LABEL source 1 " & "'" & strFname & "'." & vbCr strCmd = strCmd & "VARIABLE LABEL source 'path=" & strPath & "'." & vbCr strCmd = strCmd & "EXECUTE." objSpssApp.ExecuteCommands strCmd , True 'Combine the other files intFileNb = 2 While strFname <> "" strFname = Dir$() If strFname <> "" Then strCmd = "ADD FILES /FILE=* /FILE='" & strPath & strFname & "'." & vbCr strCmd = strCmd & "IF MISSING(source) source=" & intFileNb & "." & vbCr strCmd = strCmd & "ADD VALUE LABEL source " & intFileNb & " '" & strFname & "'." & vbCr strCmd = strCmd & "EXECUTE." Debug.Print strCmd objSpssApp.ExecuteCommands strCmd , True intFileNb = intFileNb + 1 End If Wend ' Save the combined file strCmd = "SAVE OUTFILE='" & strPath & "combined file.sav'." & vbCr strCmd = strCmd & "EXECUTE." objSpssApp.ExecuteCommands strCmd , True End Sub