Data Model > Available DSCs > SPSS Statistics SAV DSC > Writing to an SPSS Statistics .sav file > Variable names and labels when writing to a .sav file
 
Variable names and labels when writing to a .sav file
The .sav files written by the SPSS Statistics SAV DSC support variable names up to 64 bytes in length. This typically means a maximum of 64 characters in single-byte languages, such as English, French, and German, and a maximum of 32 characters in double-byte languages, such as Japanese, Chinese, and Korean.
IBM SPSS Statistics versions prior to version 12 support variable names up to eight bytes in length only and will truncate names longer than this, which can result in duplicate variable names. If you intend to open your .sav file in a version of IBM SPSS Statistics prior to version 12, use the MaxVarNameLen property (see Properties and settings used by the SPSS Statistics SAV DSC to specify that the maximum length for variable names is eight bytes.
How the SPSS Statistics SAV DSC generates variable names
The first character of an IBM SPSS Statistics variable name must be a letter or one of the characters @, #, or $. Subsequent characters can be any combination of letters, numbers, a period (.), and nonpunctuation characters.
The SPSS Statistics SAV DSC bases the IBM SPSS Statistics variable names on the aliases stored for the mrSavDsc DataSource in the MDM document. These aliases, which are generated by an algorithm that defines the rules for IBM SPSS Statistics variable names, are stored by the when the MDM document is first used to create a .sav file. Sometimes a single MDM variable (that is, a multiple-response categorical variable) maps to more than one IBM SPSS Statistics variable, and an additional algorithm is used to create multiple aliases, which are known as subaliases.
The algorithm used to create aliases uses the value of the MDM variable instance's FullName property as its starting point. Consider a loop called Loop1 that has a controlling category list that consists of categories called Brand1 and Brand2, and which has questions Q1 and Q2. The FullNames of the variable instances are:
Loop1[{Brand1}].Q1
Loop1[{Brand1}].Q2
Loop1[{Brand2}].Q1
Loop1[{Brand2}].Q2
The FullNames of the variable instances in a grid are similar to those in a loop.
Note The following is a simplified and approximate representation of the alias algorithm. In practice the details may differ.
The SPSS Statistics SAV DSC alias algorithm:
Starts with the variable instance's FullName.
Replaces square brackets ([]), braces ({}), parentheses (()), spaces, and combinations of these characters with underscores (_). If any of these characters appear at the start of a name, they are removed. Most of the remaining characters in the FullName are valid.
Removes any periods (.). Although periods are valid in IBM SPSS Statistics variable names, the replaces them because of conflicts with other tools, such as Data Transformation Services (DTS).
Removes duplicate underscores.
Prefixes names that start with a number or the _#$ characters with the at sign (@).
Removes duplicate at signs.
Replaces any remaining characters that are invalid in IBM SPSS Statistics variable names. The names are then in the form Loop1_Brand1_Q1, Loop1_Brand1_Q1, and so on.
Starts to deal with the maximum length for variable names by using an algorithm that divides the name up into sections separated by uppercase letters, at signs, and underscore characters. It then truncates each section so that the overall size is no larger than the maximum length for variable names. For example, if the maximum length for variable names is eight, Hello_World@Home becomes HeWorHom.
If the alias is not unique, it removes a character based on the algorithm in the previous step, adds a number to the end of the alias and tries again.
The SPSS Statistics SAV DSC generates an error if an alias is longer than the maximum length for variable names, and does not create or write the corresponding column.
The SPSS Statistics SAV DSC stores the alias in the MDM variable instance's AliasName property, and stores subaliases in the SubAliasName property. See also IVariableInstance.AliasName and IVariableInstance.SubAliasName in the MDM Object Model Reference.
You can control some aspects of the way in which the SPSS Statistics SAV DSC generates IBM SPSS Statistics variable names by using the AliasCutFactor and AliasRetryLimit properties (see Properties and settings used by the SPSS Statistics SAV DSC).
See also
Variable labels
Writing to an SPSS Statistics .sav file