intrleav#

Purpose#

Interleaves the rows of two GAUSS dataset files that have been sorted on a common variable to produce a single file sorted on that variable.

Format#

intrleav(infile1, infile2, outfile, keyvar, keytyp)#
Parameters:
  • infile1 (string) – name of input file 1.

  • infile2 (string) – name of input file 2.

  • outfile (string) – name of output file.

  • keyvar (string) – name of key variable; this is the column the files are sorted on.

  • keytyp (scalar) –

    data type of key variable.

    1

    numeric key, ascending order

    2

    character key, ascending order

    -1

    numeric key, descending order

    -2

    character key, descending order

Examples#

// Varnames
varnames = "id"$|"x"$|"y";

// Create first data file
id1 = seqa(1, 1, 100);
x1 = rndn(100, 1);
y1 = rndn(100, 1);
saved(id1~x1~y1, "mydata_1.dat", varnames);

// Create second data file
id2 = seqa(101, 1, 100);
x2 = rndn(100, 1);
y2 = rndn(100, 1);
saved(id2~x2~y2, "mydata_2.dat", varnames);

// Interleave both files into one

// Define infiles
infile1 = "mydata_1.dat";
infile2 = "mydata_2.dat";

// Define key variable for merging
keyvar = "id";

/*
** Define key variable type
** 1    Numeric, ascending order
** 2    Character, ascending order
** 3    Numeric, descending order
** 4    Character, descending order
*/
keytyp = 1;

// Define outfile name
outfile = "mydata_total.dat";

/*
** Combine both infiles using
** intrleave to form one outfile
*/
intrleav(infile1, infile2, outfile, keyvar, keytyp);

Remarks#

The two files MUST have exactly the same variables; that is, the same number of columns AND the same variable names. They must both already be sorted on the key column. This procedure will combine them into one large file, sorted by the key variable.

If the inputs are null ("" or 0), the procedure will ask for them.

Source#

sortd.src

See also

Functions intrleavsa()