Obsidian | Level 7

## How do I write not equal to a negative number?

How do I write not equal to a negative number? I want to include zeros, positive numbers, and null values. Basically I want to only exclude anything that has "-" in front of a number.

1 ACCEPTED SOLUTION

Accepted Solutions
Super User

## Re: How do I write not equal to a negative number?

Since you want to include the missing values you will need to test for missing values separately.

``where x>=0 or missing(x) ;``

If you wanted to exclude positive values (keeping missing and negative values) it would be easier because missing values are smaller than all actual numbers so you could just use:

``where x <=0 ;``

So you could use negate the value and use that test:

```2125  data _null_;
2126    do x=.,.z,-1,0,1 ;
2127      test1 = (x >= 0) or missing(x);
2128      test2 = -x <= 0 ;
2129      put x= test1= test2= ;
2130    end;
2131  run;

x=. test1=1 test2=1
x=Z test1=1 test2=1
x=-1 test1=0 test2=0
x=0 test1=1 test2=1
x=1 test1=1 test2=1
NOTE: Missing values were generated as a result of performing an operation on missing values.
Each place is given by: (Number of times) at (Line):(Column).
2 at 2128:14
NOTE: DATA statement used (Total process time):
real time           0.00 seconds
cpu time            0.00 seconds
```

But notice that it causes notes to be generated when there are missing values since it is performing the negation operation on the value.

4 REPLIES 4
PROC Star

## Re: How do I write not equal to a negative number?

There is no such thing as null values in SAS. I assume you mean missing values. This should do it:

``where MyNumber = . or MyNumber >= 0;``
Super User

## Re: How do I write not equal to a negative number?

Since you want to include the missing values you will need to test for missing values separately.

``where x>=0 or missing(x) ;``

If you wanted to exclude positive values (keeping missing and negative values) it would be easier because missing values are smaller than all actual numbers so you could just use:

``where x <=0 ;``

So you could use negate the value and use that test:

```2125  data _null_;
2126    do x=.,.z,-1,0,1 ;
2127      test1 = (x >= 0) or missing(x);
2128      test2 = -x <= 0 ;
2129      put x= test1= test2= ;
2130    end;
2131  run;

x=. test1=1 test2=1
x=Z test1=1 test2=1
x=-1 test1=0 test2=0
x=0 test1=1 test2=1
x=1 test1=1 test2=1
NOTE: Missing values were generated as a result of performing an operation on missing values.
Each place is given by: (Number of times) at (Line):(Column).
2 at 2128:14
NOTE: DATA statement used (Total process time):
real time           0.00 seconds
cpu time            0.00 seconds
```

But notice that it causes notes to be generated when there are missing values since it is performing the negation operation on the value.

Super User

## Re: How do I write not equal to a negative number?

Provide some examples of values an results of how you are using this.

There are often several ways to accomplish things in SAS and know what you want and how that result is used might point us to a more flexible method than one that "works" for a very small use case.

Super User

## Re: How do I write not equal to a negative number?

``````/*Or try SIGN() function*/
data have;
input x;
if sign(x)=-1 then delete;
cards;
98
0
.
-98
;``````
Discussion stats
• 4 replies
• 552 views
• 2 likes
• 5 in conversation