Example of interleaving data from multiple data files

The attached spec INTERLEAVE.SPX will read 3 data files and interleave data records into the output file so that the first file will end up with records 1,4,7, etc in the output file. The second file will end up with records 2,5,8, etc and the third file will end up with 3,6,9,etc.

If some of the three files have more than the others, the procedure will continue writing out records in the longer files, until there are no records left.

Change the input lines to have your file names on it. Do not change the study= settings.

You can run this on any number of files by changing NumFiles to the correct number of files and adding the proper number of ~Input file commands.

>PurgeSame>Define @NumFiles 3~In  Interleave.Dta ,ASCII=80,NumBuf=@NumFiles,Study=File1~In  Interleave.Dtb ,ASCII=80,NewBuf,Study=File2~In  Interleave.Dtc ,ASCII=80,NewBuf,Study=File3~Out Interleave.All ,ASCII,TrimBlanks~DefProc=Combo:If FirstCase>Repeat $A=2,...,@NumFilesChooseFile "file$A"Next>EndRepChooseFile "File1"EndifWriteCase>Repeat $A=2,...,@NumFilesChooseFile "File$A"If File$A!Eof_Data ElseWriteCaseNextEndif>EndRepExEofWhile MaxTimes=100000 True>Repeat $A=2,...,@NumFilesChooseFile "File$A"If File$A!Eof_Data ElseWriteCaseNextEndif>EndRepeatIf &>Repeat $A=2,...,@NumFiles; Strip="And &"File$A!Eof_Data And &>EndRepeatGoto DoneEndifEndWhileDone:}~Exc Proc=Combo on file1~End

  • interleave.zip