IBM Support

Adjust string widths across files before merging

Question & Answer


I want to merge two files (Add Cases) in SPSS Statistics, but the widths for for certain string variables differ across the files. Is there a way that I can adjust the widths for all string variables from the second file to match the widths for the corresponding variables in the first file without having to specify the width for each of these variables in the Variable View or by syntax commands?


You can perform this task with the STATS ADJUST WIDTHS extension command, which adjusts the string widths in a file to match the string widths in the active data set. You need to have the Python
Essentials installed, which are installed by default with SPSS Statistics in versions 22 and above. For earlier versions of SPSS Statistics, the Python Essentials can be downloaded from here and individual extension commands can be downloaded from here. Once these elements are installed, the dialog for the STATS ADJUST WIDTHS extension is in the Data menu as Adjust String Widths Across Files .

Suppose that you have a pair of data files from related surveys and that you wish to merge the files in an ADD CASES merge. Suppose also that the widths of string variables Region and City are 12
and 20 characters respectively, in survey1.sav; 15 and 30, in survey2.sav. In the following commands, with survey1.sav as the active file, the widths in survey2.sav are adjusted to 12 and 20 characters and the adjusted survey2 dataset is then merged with survey1.sav. The merged file is then saved as Survey1_2merged.sav.

/FILES * "C:\Surveys\Survey2.sav".


SAVE OUTFILE='C:\Surveys\Survey1_2.sav'

The * in the /FILES subcommand of the STATS ADJUST WIDTHS command refers to the active data set when the command is run.

[{"Product":{"code":"SSLVMB","label":"SPSS Statistics"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":"--","Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"Not Applicable","Edition":"","Line of Business":{"code":"LOB10","label":"Data and AI"}}]

Document Information

Modified date:
16 April 2020