SAS: How to Use the IN Operator

The IN operator in SAS is used to compare a value against a list of values. It allows you to select multiple values from a SAS dataset. It is an alternative of multiple OR conditions.

The syntax for using the IN operator in SAS is as follows:

variable IN (value1, value2, ..., valueN)

Here values of the variable will be compared against the list of values - (value1, value2, ..., valueN)

How to use IN Operator in DATA STEP in SAS

The following code filters the dataset based on the values of the MAKE variable. It selects cars of these 3 brands 'Audi', 'Acura', 'BMW' and puts them into a new dataset named "newdata".

data newdata;
where make in('Audi', 'Acura', 'BMW');

To check if the above code filters dataset correctly, we can use the PROC FREQ procedure to see the unique values of the column MAKE.

proc freq data=newdata;
table make;
How to Use the IN Operator in SAS

How to use IN Operator in PROC SQL in SAS

proc sql;
select *
where make in('Audi', 'Acura', 'BMW');

How to use NOT IN Operator in SAS

The NOT IN operator is used in SAS to filter rows based on the condition that a column does not match any of the values. The following code returns all cars that have makers not included in the list - 'Audi', 'Acura', 'BMW'.

proc sql;
select *
where make not in('Audi', 'Acura', 'BMW');
Related Posts
Spread the Word!
About Author:
Deepanshu Bhalla

Deepanshu founded ListenData with a simple objective - Make analytics easy to understand and follow. He has over 10 years of experience in data science. During his tenure, he worked with global clients in various domains like Banking, Insurance, Private Equity, Telecom and HR.

0 Response to "SAS: How to Use the IN Operator"

Post a Comment

Next → ← Prev
Looks like you are using an ad blocker!

To continue reading you need to turnoff adblocker and refresh the page. We rely on advertising to help fund our site. Please whitelist us if you enjoy our content.