Next: , Previous: IMPORT, Up: System and Portable Files



7.5 MATCH FILES

     MATCH FILES
             /{FILE,TABLE}={*,'filename'}
             /DROP=var_list
             /KEEP=var_list
             /RENAME=(src_names=target_names)...
             /IN=var_name
     
             /BY var_list
             /FIRST=var_name
             /LAST=var_name
             /MAP

MATCH FILES merges one or more system files, optionally including the active file. Records with the same values for BY variables are combined into a single record. Records with different values are output in order. Thus, multiple sorted system files are combined into a single sorted system file based on the value of the BY variables. The results of the merge become the new active file.

The BY subcommand specifies a list of variables that are used to match records from each of the system files. Variables specified must exist in all the files specified on FILE and TABLE. BY should usually be specified. If TABLE or IN is used then BY is required.

Specify FILE with a system file as a file name string or file handle (see FILE HANDLE), or with an asterisk (*) to indicate the current active file. The files specified on FILE are merged together based on the BY variables, or combined case-by-case if BY is not specified. Normally at least two FILE subcommands should be specified.

Specify TABLE with a system file to use it as a table lookup file. Records in table lookup files are not used up after they've been used once. This means that data in table lookup files can correspond to any number of records in FILE files. Table lookup files correspond to lookup tables in traditional relational database systems. It is incorrect to have records with duplicate BY values in table lookup files.

Any number of FILE and TABLE subcommands may be specified. Each instance of FILE or TABLE can be followed by any sequence of DROP, KEEP, or RENAME subcommands. These have the same form and meaning as the corresponding subcommands of GET (see GET), but apply only to variables in the given file.

Each FILE or TABLE may optionally be followed by an IN subcommand, which creates a numeric variable with the specified name and format F1.0. The IN variable takes value 1 in a case if the given file contributed a row to the merged file, 0 otherwise. The DROP, KEEP, and RENAME subcommands do not affect IN variables.

Variables belonging to files that are not present for the current case are set to the system-missing value for numeric variables or spaces for string variables.

FIRST, LAST, and MAP are currently ignored.

MATCH FILES may not be specified following TEMPORARY (see TEMPORARY) if the active file is used as an input source.