SPSS Metadata
Data about data. SPSS stores metadata within it's 'fat' proprietary format (i.e. SAV). This includes formats, display alignment and width, variable and value labels, measure types (i.e. scale), and user missing values.
For details on variable formats, see Numeric Formats and String Formats.
Examine Metadata
To extract metadata from an SPSS data set, use: display dictionary. This command works on the active data set.
It outputs (within SPSS) three tables:
- data file metadata
- variable metadata
- value label metadata
The parallel for external data files is:
sysfile info file="/path/to/file.sav".
Variable Labels
To apply labels to variables, try:
variable label foo "foo" bar "bar" baz "baz".
Value Labels
To apply labels to values, try:
add value labels foo 1 "1" 2 "2" 3 "3" /bar 1 "1" 2 "2" 3 "3" /baz "A" "A" "B" "B" "C" "C".
As demonstrated above, labels can be applied to string values.
Copy Metadata between Datasets
To copy metadata from an existing, formatted data set to another, use apply dictionary. This command works on the active data set.
***** DICT dataset *****. new file. input program. * FOO and BAR will be common variables. numeric FOO (F2). string BAR (A2). * HAM, SPAM, EGGS will either be mismatched or non-existent. numeric HAM (F8.2). string SPAM (A8). numeric EGGS (F8). end file. end input program. execute. dataset name DICT. dataset activate DICT. variable labels FOO "FOO" BAR "BAR" HAM "HAM" SPAM "SPAM" EGGS "EGGS". value labels /FOO EGGS 1 "1" 2 "2". execute. ***** NEW dataset *****. new file. input program. * FOO and BAR will be common variables. numeric FOO (F2). string BAR (A2). * HAM, SPAM, EGGS will either be mismatched or non-existent. numeric HAM (F5). string SPAM (A2). *numeric EGGS (F8). end file. end input program. execute. dataset name NEW. dataset activate NEW. apply dictionary from "DICT".
As expected, FOO and BAR have all metadata copied perfectly. The others have some unexpected behaviors.
HAM is a numeric variable with mismatched formats (F8.2 in the source, F5.0 in the target). The target has been overwritten with the source format.
SPAM is a string variable with mismatched formats (A8 in the source, A2 in the target). The source format remains.
EGGS is defined in the source, but not the target. Its metadata is not copied over. When it is created after the apply dictionary, it is bare of metadata.
If the newvars subcommand is specified, EGGS will be copied over.