Professional > Data management scripting > Getting started with Data Management scripting > 2. Setting up a filter
 
2. Setting up a filter
In the DMS file we looked at 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 is a way of defining a subset of the data to be transferred. The filter can restrict the variables that are included 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 included in the transfer only if their serial number is less than 101. Respondent.Serial is a special variable (called a system variable) that is present 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 will change the MyFirstTransfer.dms sample file, so you may 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 above to:
SelectQuery = "SELECT age, gender, education, remember
    FROM VDATA _ WHERE gender = {female}"
This filter will restrict the transfer to the four named variables (age, gender, education, and remember) and case data records for female respondents only.
If we use this filter for the transfer, the structure of the data will not match the structure of the data we transferred before. If we try to export it to the same .sav file, we will get an error. So before you run the transfer, you need to move or delete the files created by the previous export, or specify a different name for the output files. We will change the name of the output files. To do this, 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 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. You will see that 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, you will see that 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 If you are new to writing SQL queries, see the Basic SQL Queries, Running the Example Queries in DM Query, and DM Query topics in the UNICOM Intelligence Developer Documentation Library.
Note
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
The next topic shows how to transfer other types of data. See 3. Transferring different types of data.
See also
Getting started with Data Management scripting