There are three operators for ‘not equal’ in SAS. You can use ne, ^=, or ~= to check if a variable is not equal to another variable or value.

data k;
    a = 'string';
    if a ne 'another string' then put 'a not equal to "another string" with ne';
    if a ^= 'another string' then put 'a not equal to "another string" with ^=';
    if a ~= 'another string' then put 'a not equal to "another string" with ~=';
run;

/* Output: */
 a not equal to "another string" with ne
 a not equal to "another string" with ^=
 a not equal to "another string" with ~=

When working in SAS, logical operators allow us to control the flow of our data.

There are many different logical operators which allow us to perform checks on the values of variables.

One common operation is to check if a variable is not equal to another variable or value.

There are three different ways you can check if a variable is not equal to another in a SAS data step.

You can use ne, ^=, or ~= to check if a variable is not equal to another variable or value.

Below are some examples of how you can use SAS to check if a variable is not equal to another in a data step.

data k;
    a = 'string';
    if a ne 'another string' then put 'a not equal to "another string" with ne';
    if a ^= 'another string' then put 'a not equal to "another string" with ^=';
    if a ~= 'another string' then put 'a not equal to "another string" with ~=';
run;

/* Output: */
 a not equal to "another string" with ne
 a not equal to "another string" with ^=
 a not equal to "another string" with ~=

Checking if a Variable Value is NOT IN a List of Values

The SAS not equal operator allows us to check if a variable is not equal to one value. If you want to check against a collection of values, you can use the SAS not operator in combination with the in operator.

Below is an example of how to check if a variable is NOT IN a list of values in SAS.

data k;
    a = 4;
    if a NOT IN (1, 2, 3) then put 'a is not in (1, 2, 3)';
run;

/* Output: */
 a is not in (1, 2, 3)

Hopefully this article helped you learn how to use the SAS not equal operator in a data step.

Categorized in:

SAS,

Last Update: February 26, 2024