• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Programming Expert

Solving All of Your Programming Headaches

  • HTML
  • JavaScript
  • jQuery
  • PHP
  • Python
  • SAS
  • Ruby
  • About
You are here: Home / SAS / SAS Not Equal – Check if a Variable is Not Equal to Another in Data Step

SAS Not Equal – Check if a Variable is Not Equal to Another in Data Step

April 19, 2022 Leave a Comment

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.

Other Articles You'll Also Like:

  • 1.  SAS calculated – Use Columns Created from Select in PROC SQL
  • 2.  Get the Row Number in a SAS Data Step with _n_
  • 3.  SAS prxmatch – Find Pattern in String Using Regex (Regular Expression)
  • 4.  SAS if then else – Write Conditional Expressions for Multiple Conditions
  • 5.  SAS nodupkey – How to Remove Duplicates with PROC SORT by Key
  • 6.  SAS Lowercase – Make String Lowercase with SAS lowcase function
  • 7.  SAS _n_ – How to Use the Automatic Variable _n_ in a Data Step
  • 8.  SAS data _null_ – Create a SAS Dataset with No Records and Variables
  • 9.  nodup vs nodupkey PROC SORT Options in SAS
  • 10.  SAS left() Function – Left Align Character Variables in Data Step

About The Programming Expert

The Programming Expert is a compilation of a programmer’s findings in the world of software development, website creation, and automation of processes.

Programming allows us to create amazing applications which make our work more efficient, repeatable and accurate.

At the end of the day, we want to be able to just push a button and let the code do it’s magic.

You can read more about us on our about page.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

About The Programming Expert

the programming expert main image

Welcome to The Programming Expert. We are a group of US-based programming professionals who have helped companies build, maintain, and improve everything from simple websites to large-scale projects.

We built The Programming Expert to help you solve your programming problems with useful coding methods and functions in various programming languages.

Search

Learn Coding from Experts on Udemy

Looking to boost your skills and learn how to become a programming expert?

Check out the links below to view Udemy courses for learning to program in the following languages:

Copyright © 2023 · The Programming Expert · About · Privacy Policy