Desktop User Guides > Professional > Data management scripting > Transferring data using a DMS file > Writing data > Transferring data to IBM SPSS Statistics
 
Transferring data to IBM SPSS Statistics
This topic provides some notes on using a DMS file to transfer case data to a .sav file. The DMS file uses the SPSS Statistics SAV DSC to write the data to the .sav file.
Writing to a new .sav file
If the .sav file you specify in the OutputDataSource section does not exist, SPSS Statistics SAV DSC will create a new .sav file.
Writing to an existing .sav file
A DMS file can be used to write data to an existing .sav file if it is empty. If it is not empty, the export succeeds only if all of the following are true:
You have exported to that file previously.
You are using the same .mdd file for the export as was used previously. If the first export was done using a DMS file, use the output metadata file from that export as the input metadata source for the second and subsequent transfers.
There has been no change in the structure of the data since the previous export. This means that the select query in the InputDataSource section in the second and subsequent transfers must specify the same variables that were specified for the first transfer.
However, SPSS Statistics SAV DSC cannot update the data that was transferred previously, and merely appends the new case data records to the end of the file. Be careful not to create duplicate records in the .sav file by exporting the same case data to it more than once.
If you are using a DMS file to write to an existing .sav file that was created using a version of the UNICOM Intelligence Data Model from versions 3.0 to 5.5, the transfer might fail because the variables are not being output in the same order as before. In versions 3.0 to 5.5, the order of the variables in the output data source was determined by the variable order in the SelectQuery statement in the DMS file's InputDataSource section. To resolve this problem, reorder the Select Query's variable order in the DMS file's InputDataSource section, or transfer the old .sav file to a new .sav file using the new Select Query (this allows you to append data).
SPSS WebApp file
In addition to the .sav file, SPSS Statistics SAV DSC automatically creates an XML file that provides additional information for use with SPSS WebApp. This XML file has the same name as the .sav file, but with the addition of an .xml filename extension. If a file of that name already exists in the same location, SPSS Statistics SAV DSC overwrites it without issuing a warning.
Customizing the output files
You can customize both the XML file and the variables in the .sav file by setting custom properties in the metadata that is specified in the InputDataSource section. Typically, you do this in the OnBeforeJobStart Event section. For more information, see Variable names and labels when writing to a .sav file.
You can also customize the .sav output by setting the SavCodePage and SavLanguage properties to support different code pages or multiple code pages. For more information, see Language handling by the SPSS Statistics SAV DSC.
Variable names
Generally, SPSS Statistics SAV DSC cannot use the same names for the variables in the .sav file as in the metadata because the variable-naming rules are different. SPSS Statistics SAV DSC automatically creates names that conform to the IBM SPSS Statistics variable-naming rules. These IBM SPSS Statistics-specific names are called aliases and are stored in the output metadata. This means that if you want to use the same names for a subsequent export, you need to use the output metadata file from the previous export as the input metadata source for the new transfer.
You can customize the aliases. You typically do this in the OnBeforeJobStart Event section. For more information, see Variable names and labels when writing to a .sav file.
You can set up custom properties and customize the aliases, only if you are using a Metadata Document (.mdd) file in the InputDataSource section.
Output metadata
Save the output metadata file, whenever possible. If you subsequently want to read the .sav file using the UNICOM Intelligence Data Model, use the .mdd file, because this gives you access to the original UNICOM Intelligence Data Model variable names. In addition, if you subsequently want to export additional records to the same .sav file, you can do so only if you run the export using the output metadata from the previous export as the input metadata source.
Transferring case data without a metadata source
Transferring data to a .sav file without specifying a metadata source in the InputDataSource section is generally possible only when you are reading the data using a non-UNICOM Intelligence OLE DB Provider. When there is no metadata source, SPSS Statistics SAV DSC cannot create and store the alias names and uses only the first eight characters of the names from the input file. This means that an error occura if the first eight characters of any of the variable names contain characters that are not allowed in IBM SPSS Statistics variable names or if there are any duplicates. Problems also occur when using SPSS Statistics SAV DSC in UNICOM Intelligence Data Model 2.9 or earlier if any text variables store texts that are longer than 255 characters because of the limit in IBM SPSS Statistics 12 and earlier. When you use the UNICOM Intelligence Data Model to read the data to be transferred, always specify an input metadata source.
Exporting dirty data
When you run the export in clean mode, SPSS Statistics SAV DSC issues errors when it finds incorrect and inconsistent data and this can make the export of those records fail. If you want to export the data as it is and clean it in IBM SPSS Statistics, select dirty mode or switch off validation altogether. For more information, see Validation options when transferring data.
Setting up weighting
Because SPSS Statistics SAV DSC can update the records in the .sav file, you can use the Weight component to set up weighting in the .sav file. The DDL includes a data management script called SavWeighting.dms, which demonstrates how to add weights to a .sav file. For more information, see Sample DMS files.
Working with Japanese characters
DMS files has only limited support for Japanese characters when working with .sav files. If the names of any of the variables that you export contain Japanese characters, the Japanese characters might be incorrect in the .sav file. You must correct the variable names manually in the Japanese language version of IBM SPSS Statistics.
Exporting to IBM SPSS Statistics
In the connection string in the OutputDataSource section, specify mrSavDsc for the Data Source property and the name and location of the .sav file for the Location property. For example:
OutputDataSource(myOutputDataSource, "My output data source")
ConnectionString = "Provider=mrOleDB.Provider.2; _
Data Source=mrSavDsc; _
Location= [INSTALL_FOLDER]\IBM\SPSS\DataCollection\7\DDL\
                Output\museum.sav
MetaDataOutputName = [INSTALL_FOLDER]\IBM\SPSS\DataCollection\7\
                        DDL\Output\museum.mdd"
End OutputDataSource
Example
This example shows a DMS file that contains an OnBeforeJobStart Event sectionOnBeforeJobStart Event section that sets up custom properties in the input metadata to customize both the .sav file and the WebApp .xml file. The custom properties are written to the Document.Properties collection because, although SPSS Statistics SAV DSC reads the custom properties from the DataSourceProperties collections, these are inherited from the Properties collection. If you want custom properties to be available for the current MDM DataSource only, write the custom properties to the DataSourceProperties collections. However, this requires first checking whether the DataSource object exists, and if it doesn't creating a new one. For an example of doing this for Quantum DSC, see OnBeforeJobStart Event section. You must also do this if you want to customize the aliases because the VariableInstance.AliasName and VariableInstance.SubAliases properties are also specific to a specified DataSource object.
For more information about setting custom properties in general and the custom properties used by SPSS Statistics SAV DSC, see MDM custom properties.
#define COPY_OF_MUSEUM_MDD "C:\Program Files\IBM\SPSS\DataCollection\7\DDL\Output\museum.mdd"

Event(OnBeforeJobStart, "Set up the custom properties")
Dim MDM, fso, f

' Create a copy of museum.mdd
Set fso = CreateObject("Scripting.FileSystemObject")
fso.CopyFile("C:\Program Files\IBM\SPSS\DataCollection\7\DDL\Data\Data Collection File\museum.mdd", _
COPY_OF_MUSEUM_MDD, True)

' Make sure that the read-only attribute is not set
Set f = fso.GetFile(COPY_OF_MUSEUM_MDD)
If f.Attributes.BitAnd(1) Then
f.Attributes = f.Attributes - 1
End If

Set MDM = CreateObject("MDM.Document")
MDM.Open(COPY_OF_MUSEUM_MDD)

MDM.Contexts.Add("SAV")
MDM.Contexts.Current = "SAV"
MDM.Properties.Item["DichotomyLabelYes"] = "Oui"
MDM.Properties.Item["DichotomyLabelNo"] = "Non"

MDM.Contexts.Add("WebApp")
MDM.Contexts.Current = "WebApp"
MDM.Properties.Item["SecurityGroups"] = "World;LocalUser;WanUser"

MDM.Save()
MDM.Close()

End Event

InputDataSource(Input)
ConnectionString = "Provider=mrOleDB.Provider.2; _
Data Source=mrDataFileDsc; _
Location=C:\Program Files\IBM\SPSS\DataCollection\7\DDL\Data\Data Collection File\museum.ddf; _
Initial Catalog=" + COPY_OF_MUSEUM_MDD
SelectQuery = "SELECT serial, age, gender, before, biology, distance, _
education, entrance, expect, visits, adults, museums, plan, similar, _
certificat, location, who_with, resident, when_decid, _
why_decid, plan_time, know_way, find_way _
FROM VDATA WHERE serial < 101"
End InputDataSource

OutputDataSource(myOutputDataSource)
ConnectionString = "Provider=mrOleDB.Provider.2; _
Data Source=mrSavDsc; _
Location=C:\Program Files\IBM\SPSS\DataCollection\7\DDL\Output\SavCustomization.sav"
MetaDataOutputName = "C:\Program Files\IBM\SPSS\DataCollection\7\DDL\Output\SavCustomization.mdd"
End OutputDataSource
This example is provided as a sample DMS file (called SavCustomization.dms). For more information, see Sample DMS files.
See
Writing data