This tutorial explains various ways to use the 'not equal to' operator in SAS, along with examples.
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;
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;
In SAS, ne symbol means "not equal to".
data outdata; set sashelp.cars; if make ne "Audi"; run;
In SAS, ~= symbol means "not equal to".
data outdata; set sashelp.cars; if make ~= "Audi"; run;
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;
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;
Share Share Tweet