Filtering Data

Creating a Filter

When you query data, you might want to retrieve only rows that meet certain criteria, based on values of columns in the data. The process of telling SAS Studio which rows to retrieve is called setting a filter and is done on the Filter tab. This corresponds to using a WHERE clause in an SQL query.
  1. In the query window, click the Columns tab to view the list of columns from the tables in the query.
  2. You can add one or more columns to the filter by dragging them from the columns list to the Filter tab. You can also click Add button on the Filter tab toolbar and select one or more columns from the Choose Column window.
  3. Select a comparison operator from the Operator drop-down list. The default value is Equals.
    Query Window with a Greater Than Operator Selected
  4. If the operator that you have selected requires a value, click Find values button to enter or select a value in the Select Value window. To choose from a list of values, click Expand list button to expand the Value list. Select the values that you want to use and click Add.
    Note: If you are selecting values for a character column, and you want the values to be enclosed in single quotation marks, select the Enclose values in quotes option. This option is selected by default. If you are using a macro variable or other value that is evaluated when the filter is run, you should clear this option.
    If you want to choose from a list of columns, click Expand list button to expand the Column list. Select the column that you want to use and click Add.
    Query Window with Selected Value for Filter
  5. Click OK to add the values to the filter.

Changing the Relationship between Filters

You can use only one column in a filter, or you can use multiple columns to create several comparison expressions. If you create more than one comparison expression in your filter, then the default relationship between these filter elements is AND. You can change the relationship between filter elements from AND to OR, and you can group elements together.
To change the relationship between filters:
  • On the Filter tab, click the relationship value and select a new value.
Query Window with the Filter Relationship