This article describes how to create a complicated filter with nested conditions. You can also use this method to create new binary variables, regardless of whether or not they're used as filters. Filters can be created out of any of the below data types:
- Numeric ranges
- Single and multiple-response categories
- Aggregated and calendar date period ranges
- Text content
In this article, we wish to create a filter for the following set of conditions:
- Gender = Female
- Age < 40
- Prefer Cola = Diet Colas (Coke Zero, Diet Coke, Diet Pepsi, Pepsi Max)
Requirements
- A variable or set of variables to be included in a filter.
Method
A filter can be created using any type of data using Create > Variables and Questions > Variable(s) > Binary - Complicated Variable. See Binary Variable or the relevant Online Training modules for more information.
- From the toolbar, select Create > Variables and Questions > Variable(s) > Binary - Complicated Variable
- Specify a Name and Label for the filter variable. In this example, we won't change the variable name but will change the Label to Females_Young_Diet Colas
- Specify a logical expression. In this example, we will need to define three conditions, all of which must be true to select a case. These are the steps:
- At the top of the screen start by clicking . You will notice that the plus sign to the left of it turned Green. We will use this tool to create the structure for our logical expression.
- Click the three times.
Now we are ready to define our three filter terms. - Select Gender from the Variables and Questions box in the lower-left, Any of from the Contains box and Female from the Values box
- Click Undefined Filter Term on the second line.
- Select Age from the Variables and Questions box, Any of from the Contains box, and all age groups under 40 from the Values box.
- Click Undefined Filter Term on the third line.
- Select Preferred cola from the Variables and Questions box, Any of from the Contains box, and Diet Coke, Coke Zero, Diet Pepsi, and Pepsi Max from the Values box.
Notice that you can check the results in the Preview of results output in the lower-left portion of your screen:
The first respondent was selected because they met all three criteria: Female, Age < 40 and they prefer diet colas. The third and fourth respondents weren't selected because there were both too old.
- Click OK when you are satisfied that the filter is working correctly.
Edit Filter
To edit your filter variable:
- Select the Variables and Questions tab
- Right-click the row number to the left of the filter variable name
- From the menu, select Edit Variable
- Click OK after you finish making changes.
Next
How to Filter Raw Data Using R
How to Create Filters Using Date Questions
How to Filter the Rows of a Table
How to Filter Rows and Columns in a Table