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.
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.
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;
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.
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.
/*Or try SIGN() function*/
data have;
input x;
if sign(x)=-1 then delete;
cards;
98
0
.
-98
;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.