Desktop User Guides > Professional > Data management scripting > Getting started with Data Management scripting > 2. Setting up a filter
 
2. Setting up a filter
In the DMS file that is in 1. Running your first transfer, the following line is in the InputDataSource section (see also InputDataSource section):
SelectQuery = "SELECT * FROM vdata WHERE Respondent.Serial < 101"
This is called the select query and it is where you specify the filter for the transfer. A filter defines a subset of the data to be transferred. The filter can restrict the variables that are in the transfer, or the case data records, or both. In this query, the line WHERE Respondent.Serial < 101 specifies that case data records should be in the transfer only if their serial number is less than 101. Respondent.Serial is a special variable (called a system variable) that is in most UNICOM Intelligence data and which stores the respondent's serial number.
Now change the filter to restrict the transfer to a few specific variables and different case data records. Doing this changes the MyFirstTransfer.dms sample file, so you might want to make a backup copy of it first.
1 If its not already open, open MyFirstTransfer.dms in UNICOM Intelligence Professional and change the line shown to:
SelectQuery = "SELECT age, gender, education, remember
    FROM VDATA _ WHERE gender = {female}"
This filter restricts the transfer to the four named variables (age, gender, education, and remember) and case data records for female respondents only.
If you use this filter for the transfer, the structure of the data will not match the structure of the data that you transferred before. If you try to export it to the same .sav file, an error occurs. So before you run the transfer, move or delete the files created by the previous export, or specify a different name for the output files. To change the name of the output files, change the OutputDataSource section as follows (the changes are highlighted):
OutputDataSource(myOutputDataSource)
  ConnectionString = "Provider=mrOleDB.Provider.2; _
    Data Source=mrSavDsc; _
    Location=[INSTALL_FOLDER]\IBM\SPSS\DataCollection\7\DDL\ _
    Output\MyFirstTransfer2.sav"
    MetaDataOutputName =         "[INSTALL_FOLDER]\IBM\SPSS\DataCollection\7\DDL\ _
         Output\MyFirstTransfer2.mdd"
End OutputDataSource
2 Save the file with a new name, for example, MyFirstTransfer2.dms.
3 Press Ctrl+F5 to run the transfer without debugging, and then click the Output tab, so that you can see the Output pane.
4 If you have IBM SPSS Statistics, use it to open the .sav file after the transfer has finished.
This time only the variables in the select query have been transferred. However, some numeric variables have been created for the remember variable, because it is a multiple response variable. If you have the IBM SPSS Statistics Tables add-on module, a multiple response set called $remembe has also been created for this variable. For more information, see Variable definitions when writing to a .sav file.
5 For more information about writing SQL queries, see Basic SQL Queries, Running the Example Queries in DM Query, and DM Query in the UNICOM Intelligence Developer Documentation Library.
Copying queries into a DMS file
You can copy queries in DM Query and paste them straight into a DMS file. Paste the query after the equal sign like this:
SelectQuery = "<paste the query here>"
For more information, see Filtering data in a DMS file.
Next
3. Transferring different types of data.
See
Getting started with Data Management scripting