Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Home
- /
- Programming
- /
- Programming
- /
- How do I write not equal to a negative number?

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

☑ This topic is **solved**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 10-26-2022 07:49 PM
(551 views)

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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;`

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

```
/*Or try SIGN() function*/
data have;
input x;
if sign(x)=-1 then delete;
cards;
98
0
.
-98
;
```

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. **Registration is now open through August 30th**. Visit the SAS Hackathon homepage.

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.