* QUESTION: I have a file which contains the name of about 300 files. Most of these files are in 20 folders. How can I process all these files? * ANSWER by rlevesque@videotron.ca. *Replace path in next line by your path. DEFINE !path()"D:\\data\\"!ENDDEFINE. *************. *Prepare dummy files to illustrate the solution. *************. DATA LIST LIST /fdrname(A12). BEGIN DATA "folder1" "folderb" "last folder" END DATA. LIST. *The next file would contain the names of the 20 folders. SAVE OUTFILE=!path + "Folder names.sav". DATA LIST LIST /fname(A12). BEGIN DATA "file1" "file2" "another file" "last file" END DATA. LIST. * This file would countain the list of the 300 files names. SAVE OUTFILE=!path + "File names.sav". * each of the 300 files is in most (but not necessarily all) of the 20 folders. * Make dummy data files. DATA LIST FREE /dummy. BEGIN DATA 1 2 3 4 5 END DATA. *NOTE: each file must exist in FIRST folder whose name appears in the folder file. * the dummy files may be made up of the variable names with no records. SAVE OUTFILE=!path + "folder1\\file1.sav". SAVE OUTFILE=!path + "folderb\\file1.sav". SAVE OUTFILE=!path + "folder1\\file2.sav". SAVE OUTFILE=!path + "folderb\\file2.sav". SAVE OUTFILE=!path + "last folder\\file2.sav". SAVE OUTFILE=!path + "folder1\\another file.sav". SAVE OUTFILE=!path + "folder1\\last file.sav". SAVE OUTFILE=!path + "folderb\\last file.sav". ********************. **** Start the job. ********************. * Prepare the Folder name file. GET FILE=!path + "Folder names.sav". COMPUTE id=$CASENUM. SAVE OUTFILE=!path + "folders.sav". * Prepare the files names file. GET FILE=!path + "File names.sav". * replace 350 by a number at least as large as the number of files. LOOP id=1 TO 350. XSAVE OUTFILE=!path + "files.sav" /KEEP id fname. END LOOP. EXECUTE. GET FILE=!path + "Files.sav". SORT CASES BY id. MATCH FILES /FILE=* /TABLE='D:\\data\\folders.sav' /BY id. SELECT IF LEN(RTRIM(fdrname))>0. *Write syntax which will combine the files. SORT CASES BY fname. MATCH FILES FILE=* /BY fname /FIRST=first /LAST=last. STRING fullname(A80), savename(A20), quote(A1). COMPUTE quote="'". COMPUTE fullname=CONCAT(quote,RTRIM(fdrname),"\\",RTRIM(fname),".sav",quote). COMPUTE savename=CONCAT(quote,RTRIM(fname),".sav",quote). DO IF first. WRITE OUTFILE=!path + "syntax to combine files.sps" / 'GET FILE="' !path '" + ' fullname '.'. ELSE. WRITE OUTFILE=!path + "syntax to combine files.sps" /'ADD FILES FILE=* /FILE="' !path '" + ' fullname '.'. END IF. DO IF last. WRITE OUTFILE=!path + "syntax to combine files.sps" /'SAVE OUTFILE="' !path '" + ' savename '.'. END IF. Execute. *Then load the "syntax to combine files.sps" and run it. * NOTE that using the INCLUDE command to run the syntax * will NOT work because of the missing files.