Finish fixing MATCH FILES (PR 11677).
[pspp-builds.git] / doc / files.texi
1 @node System and Portable Files, Variable Attributes, Data Input and Output, Top
2 @chapter System Files and Portable Files
3
4 The commands in this chapter read, write, and examine system files and
5 portable files.
6
7 @menu
8 * APPLY DICTIONARY::            Apply system file dictionary to active file.
9 * EXPORT::                      Write to a portable file.
10 * GET::                         Read from a system file.
11 * IMPORT::                      Read from a portable file.
12 * MATCH FILES::                 Merge system files.
13 * SAVE::                        Write to a system file.
14 * SYSFILE INFO::                Display system file dictionary.
15 * XSAVE::                       Write to a system file, as a transform.
16 @end menu
17
18 @node APPLY DICTIONARY, EXPORT, System and Portable Files, System and Portable Files
19 @section APPLY DICTIONARY
20 @vindex APPLY DICTIONARY
21
22 @display
23 APPLY DICTIONARY FROM='filename'.
24 @end display
25
26 @cmd{APPLY DICTIONARY} applies the variable labels, value labels,
27 and missing values from variables in a system file to corresponding
28 variables in the active file.  In some cases it also updates the
29 weighting variable.
30
31 Specify a system file with a file name string or as a file handle
32 (@pxref{FILE HANDLE}).  The dictionary in the system file will be read,
33 but it will not replace the active file dictionary.  The system file's
34 data will not be read.
35
36 Only variables with names that exist in both the active file and the
37 system file are considered.  Variables with the same name but different
38 types (numeric, string) will cause an error message.  Otherwise, the
39 system file variables' attributes will replace those in their matching
40 active file variables, as described below.
41
42 If a system file variable has a variable label, then it will replace the
43 active file variable's variable label.  If the system file variable does
44 not have a variable label, then the active file variable's variable
45 label, if any, will be retained.
46
47 If the active file variable is numeric or short string, then value
48 labels and missing values, if any, will be copied to the active file
49 variable.  If the system file variable does not have value labels or
50 missing values, then those in the active file variable, if any, will not
51 be disturbed.
52
53 Finally, weighting of the active file is updated (@pxref{WEIGHT}).  If
54 the active file has a weighting variable, and the system file does not,
55 or if the weighting variable in the system file does not exist in the
56 active file, then the active file weighting variable, if any, is
57 retained.  Otherwise, the weighting variable in the system file becomes
58 the active file weighting variable.
59
60 @cmd{APPLY DICTIONARY} takes effect immediately.  It does not read the
61 active
62 file.  The system file is not modified.
63
64 @node EXPORT, GET, APPLY DICTIONARY, System and Portable Files
65 @section EXPORT
66 @vindex EXPORT
67
68 @display
69 EXPORT
70         /OUTFILE='filename'
71         /DROP=var_list
72         /KEEP=var_list
73         /RENAME=(src_names=target_names)@dots{}
74 @end display
75
76 The @cmd{EXPORT} procedure writes the active file dictionary and data to a
77 specified portable file.
78
79 The OUTFILE subcommand, which is the only required subcommand, specifies
80 the portable file to be written as a file name string or a file handle
81 (@pxref{FILE HANDLE}).
82
83 DROP, KEEP, and RENAME follow the same format as the SAVE procedure
84 (@pxref{SAVE}).
85
86 @cmd{EXPORT} is a procedure.  It causes the active file to be read.
87
88 @node GET, IMPORT, EXPORT, System and Portable Files
89 @section GET
90 @vindex GET
91
92 @display
93 GET
94         /FILE='filename'
95         /DROP=var_list
96         /KEEP=var_list
97         /RENAME=(src_names=target_names)@dots{}
98 @end display
99
100 @cmd{GET} clears the current dictionary and active file and
101 replaces them with the dictionary and data from a specified system file.
102
103 The FILE subcommand is the only required subcommand.  Specify the system
104 file to be read as a string file name or a file handle (@pxref{FILE
105 HANDLE}).
106
107 By default, all the variables in a system file are read.  The DROP
108 subcommand can be used to specify a list of variables that are not to be
109 read.  By contrast, the KEEP subcommand can be used to specify variable
110 that are to be read, with all other variables not read.
111
112 Normally variables in a system file retain the names that they were
113 saved under.  Use the RENAME subcommand to change these names.  Specify,
114 within parentheses, a list of variable names followed by an equals sign
115 (@samp{=}) and the names that they should be renamed to.  Multiple
116 parenthesized groups of variable names can be included on a single
117 RENAME subcommand.  Variables' names may be swapped using a RENAME
118 subcommand of the form @samp{/RENAME=(A B=B A)}.
119
120 Alternate syntax for the RENAME subcommand allows the parentheses to be
121 eliminated.  When this is done, only a single variable may be renamed at
122 once.  For instance, @samp{/RENAME=A=B}.  This alternate syntax is
123 deprecated.
124
125 DROP, KEEP, and RENAME are performed in left-to-right order.  They
126 each may be present any number of times.  @cmd{GET} never modifies a
127 system file on disk.  Only the active file read from the system file
128 is affected by these subcommands.
129
130 @cmd{GET} does not cause the data to be read, only the dictionary.  The data
131 is read later, when a procedure is executed.
132
133 @node IMPORT, MATCH FILES, GET, System and Portable Files
134 @section IMPORT
135 @vindex IMPORT
136
137 @display
138 IMPORT
139         /FILE='filename'
140         /TYPE=@{COMM,TAPE@}
141         /DROP=var_list
142         /KEEP=var_list
143         /RENAME=(src_names=target_names)@dots{}
144 @end display
145
146 The @cmd{IMPORT} transformation clears the active file dictionary and
147 data and
148 replaces them with a dictionary and data from a portable file on disk.
149
150 The FILE subcommand, which is the only required subcommand, specifies
151 the portable file to be read as a file name string or a file handle
152 (@pxref{FILE HANDLE}).
153
154 The TYPE subcommand is currently not used.
155
156 DROP, KEEP, and RENAME follow the syntax used by @cmd{GET} (@pxref{GET}).
157
158 @cmd{IMPORT} does not cause the data to be read, only the dictionary.  The
159 data is read later, when a procedure is executed.
160
161 @node MATCH FILES, SAVE, IMPORT, System and Portable Files
162 @section MATCH FILES
163 @vindex MATCH FILES
164
165 @display
166 MATCH FILES
167         /@{FILE,TABLE@}=@{*,'filename'@}
168         /DROP=var_list
169         /KEEP=var_list
170         /RENAME=(src_names=target_names)@dots{}
171         /IN=var_name
172
173         /BY var_list
174         /FIRST=var_name
175         /LAST=var_name
176         /MAP
177 @end display
178
179 @cmd{MATCH FILES} merges one or more system files, optionally
180 including the active file.  Records with the same values for BY
181 variables are combined into a single record.  Records with different
182 values are output in order.  Thus, multiple sorted system files are
183 combined into a single sorted system file based on the value of the BY
184 variables.  The results of the merge become the new active file.
185
186 The BY subcommand specifies a list of variables that are used to match
187 records from each of the system files.  Variables specified must exist
188 in all the files specified on FILE and TABLE.  BY should usually be
189 specified.  If TABLE or IN is used then BY is required.
190
191 Specify FILE with a system file as a file name string or file handle
192 (@pxref{FILE HANDLE}), or with an asterisk (@samp{*}) to
193 indicate the current active file.  The files specified on FILE are
194 merged together based on the BY variables, or combined case-by-case if
195 BY is not specified.  Normally at least two FILE subcommands should be
196 specified.
197
198 Specify TABLE with a system file to use it as a @dfn{table
199 lookup file}.  Records in table lookup files are not used up after
200 they've been used once.  This means that data in table lookup files can
201 correspond to any number of records in FILE files.  Table lookup files
202 correspond to lookup tables in traditional relational database systems.
203 It is incorrect to have records with duplicate BY values in table lookup
204 files.
205
206 Any number of FILE and TABLE subcommands may be specified.  Each
207 instance of FILE or TABLE can be followed by any sequence of DROP,
208 KEEP, or RENAME subcommands.  These have the same form and meaning as
209 the corresponding subcommands of @cmd{GET} (@pxref{GET}), but apply
210 only to variables in the given file.
211
212 Each FILE or TABLE may optionally be followed by an IN subcommand,
213 which creates a numeric variable with the specified name and format
214 F1.0.  The IN variable takes value 1 in a case if the given file
215 contributed a row to the merged file, 0 otherwise.  The DROP, KEEP,
216 and RENAME subcommands do not affect IN variables.
217
218 Variables belonging to files that are not present for the current case
219 are set to the system-missing value for numeric variables or spaces for
220 string variables.
221
222 FIRST, LAST, and MAP are currently ignored.
223
224 @cmd{MATCH FILES} may not be specified following @cmd{TEMPORARY}
225 (@pxref{TEMPORARY}) if the active file is used as an input source.
226
227 @node SAVE, SYSFILE INFO, MATCH FILES, System and Portable Files
228 @section SAVE
229 @vindex SAVE
230
231 @display
232 SAVE
233         /OUTFILE='filename'
234         /@{COMPRESSED,UNCOMPRESSED@}
235         /DROP=var_list
236         /KEEP=var_list
237         /VERSION=version
238         /RENAME=(src_names=target_names)@dots{}
239 @end display
240
241 The @cmd{SAVE} procedure causes the dictionary and data in the active
242 file to
243 be written to a system file.
244
245 OUTFILE is the only required subcommand.  Specify the system
246 file to be written as a string file name or a file handle (@pxref{FILE
247 HANDLE}).
248
249 The COMPRESS and UNCOMPRESS subcommand determine whether the saved
250 system file is compressed.  By default, system files are compressed.
251 This default can be changed with the SET command (@pxref{SET}).
252
253 By default, all the variables in the active file dictionary are written
254 to the system file.  The DROP subcommand can be used to specify a list
255 of variables not to be written.  In contrast, KEEP specifies variables
256 to be written, with all variables not specified not written.
257
258 Normally variables are saved to a system file under the same names they
259 have in the active file.  Use the RENAME subcommand to change these names.
260 Specify, within parentheses, a list of variable names followed by an
261 equals sign (@samp{=}) and the names that they should be renamed to.
262 Multiple parenthesized groups of variable names can be included on a
263 single RENAME subcommand.  Variables' names may be swapped using a
264 RENAME subcommand of the form @samp{/RENAME=(A B=B A)}.
265
266 Alternate syntax for the RENAME subcommand allows the parentheses to be
267 eliminated.  When this is done, only a single variable may be renamed at
268 once.  For instance, @samp{/RENAME=A=B}.  This alternate syntax is
269 deprecated.
270
271 DROP, KEEP, and RENAME are performed in left-to-right order.  They
272 each may be present any number of times.  @cmd{SAVE} never modifies
273 the active file.  DROP, KEEP, and RENAME only affect the system file
274 written to disk.
275
276 The VERSION subcommand specifies the version of the file format. Valid
277 versions are '3' and '3x'.  Version 3x system files are identical to
278 version 3 files, except that variable names greater than 8 bytes will
279 be truncated.  The default version is 3.  The VERSION subcommand is
280 optional.  There is no need ever to use it.
281
282 @cmd{SAVE} causes the data to be read.  It is a procedure.
283
284 @node SYSFILE INFO, XSAVE, SAVE, System and Portable Files
285 @section SYSFILE INFO
286 @vindex SYSFILE INFO
287
288 @display 
289 SYSFILE INFO FILE='filename'.
290 @end display
291
292 @cmd{SYSFILE INFO} reads the dictionary in a system file and
293 displays the information in its dictionary.
294
295 Specify a file name or file handle.  @cmd{SYSFILE INFO} reads that file as
296 a system file and displays information on its dictionary.
297
298 @cmd{SYSFILE INFO} does not affect the current active file.
299
300 @node XSAVE,  , SYSFILE INFO, System and Portable Files
301 @section XSAVE
302 @vindex XSAVE
303
304 @display
305 XSAVE
306         /OUTFILE='filename'
307         /@{COMPRESSED,UNCOMPRESSED@}
308         /DROP=var_list
309         /KEEP=var_list
310         /RENAME=(src_names=target_names)@dots{}
311 @end display
312
313 The @cmd{XSAVE} transformation writes the active file dictionary and
314 data to a
315 system file stored on disk.
316
317 @cmd{XSAVE} is a transformation, not a procedure.  It is executed when the
318 data is read by a procedure or procedure-like command.  In all other
319 respects, @cmd{XSAVE} is identical to @cmd{SAVE}.  @xref{SAVE}, for
320 more information on syntax and usage.
321 @setfilename ignored