The SAS PROC PRINT procedure is a powerful tool for outputting data in a variety of formats. One of its most useful features is the WHERE statement, which allows you to filter the data that is printed. In this article, we'll explore the SAS PROC PRINT WHERE statement with examples to help you understand and implement this functionality.

Before diving into the examples, let's briefly understand the syntax of the WHERE statement in PROC PRINT. The basic syntax is as follows:

```sas PROC PRINT DATA=dataset WHERE expression; RUN; ```
Understanding the WHERE Statement
The WHERE statement in PROC PRINT filters the data based on a logical expression. This expression can be a simple comparison, a range, or even a complex combination of conditions using AND, OR, and NOT operators.

In this section, we'll explore two sub-topics: simple WHERE conditions and compound WHERE conditions.
Simple WHERE Conditions

Simple WHERE conditions involve a single comparison between a variable and a value or another variable. Here's an example:
```sas DATA sales; INPUT product sales_amount; DATALINES; A 100 B 200 C 150 D 250 E 300 ; RUN; PROC PRINT DATA=sales WHERE sales_amount > 200; RUN; ```
In this example, only the observations where `sales_amount` is greater than 200 will be printed. The output will be:
``` product sales_amount ------- ----------- D 250 E 300 ```
Compound WHERE Conditions

Compound WHERE conditions combine multiple simple conditions using AND, OR, and NOT operators. Here's an example:
```sas PROC PRINT DATA=sales WHERE (product = 'B' OR product = 'D') AND sales_amount > 150; RUN; ```
In this case, the output will include observations where the `product` is either 'B' or 'D', and `sales_amount` is greater than 150. The output will be:
``` product sales_amount ------- ----------- B 200 D 250 ```
Using WHERE with Multiple Variables

You can also use the WHERE statement to filter data based on multiple variables. In this section, we'll explore two sub-topics: using multiple variables in the WHERE statement and using the IN operator.
Using Multiple Variables in the WHERE Statement




















You can use multiple variables in the WHERE statement by combining them with AND or OR operators. Here's an example:
```sas PROC PRINT DATA=sales WHERE (product = 'C' OR product = 'E') AND sales_amount > 180; RUN; ```
The output will include observations where the `product` is either 'C' or 'E', and `sales_amount` is greater than 180.
Using the IN Operator
The IN operator allows you to test if a variable is in a list of values. Here's an example:
```sas PROC PRINT DATA=sales WHERE product IN ('A', 'C', 'E'); RUN; ```
In this case, the output will include observations where the `product` is either 'A', 'C', or 'E'.
In conclusion, the SAS PROC PRINT WHERE statement is a powerful tool for filtering data and controlling the output of your SAS programs. By mastering the WHERE statement, you can efficiently extract and present the information you need from your datasets. Happy coding!