How to Use Not Equal To Condition in SAS

Deepanshu Bhalla Add Comment

This tutorial explains various ways to use the 'not equal to' operator in SAS, along with examples.

1. ^= Operator

In SAS, ^= operator means "not equal to". In this example, we are telling SAS to filter out Audi cars from the "cars" dataset in the sashelp library.

data outdata;
set sashelp.cars;
if make ^= "Audi";
run;
Not Equal To Operator in SAS

Similarly, you can use the ^= operator in the IF-THEN-ELSE statement. In this case, we are creating a binary flag (1/0) for Audi cars. It returns 1 against Audi cars else 0.

data outdata;
set sashelp.cars;
if make ^= "Audi" then Audi = 0;
else Audi = 1;
run;
2. NE Symbol

In SAS, ne symbol means "not equal to".

data outdata;
set sashelp.cars;
if make ne "Audi";
run;
3. ~= Operator

In SAS, ~= symbol means "not equal to".

data outdata;
set sashelp.cars;
if make ~= "Audi";
run;
4. NOT IN Operator

The benefit of the NOT IN operator in SAS is that it can exclude multiple values.

data outdata;
set sashelp.cars;
if make not in ("Audi");
run;

Let's say you want to filter out cars of multiple car makers - Audi and BMW. In this case, NOT IN operator is useful to negate multiple values.

data outdata;
set sashelp.cars;
if make not in ("Audi", "BMW");
run;
5. <> Operator in WHERE Statement

In a WHERE statement, the "<>" symbol is considered as "not equal to". Please make a note that <> is interpreted as the maximum of the two numeric values other than the WHERE statement.

data outdata;
set sashelp.cars;
where make <> "Audi";
run;
Related Posts
Spread the Word!
Share
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.

Post Comment 0 Response to "How to Use Not Equal To Condition in SAS"
Next → ← Prev