Hi I am looking to delete any observation with a negative value...
Generally I use:
data x; set x; if variable<0 then delete; run;
However this deletes blank observations such as '.' along with any negative values.
Does anyone know how to delete only negative values?
Unfortunately the statement below doesn't work:
data x; set x; if variable=- then delete; run;
Hi,
Just try this....I am not sure this is optimized solution or not.
data one;
input nub;
cards;
-20
-10
0
.
12
;
run;
data two;
set one;
if index(nub,'-') then delete;
run;
Thanks,
Shiva
Hi,
Just try this....I am not sure this is optimized solution or not.
data one;
input nub;
cards;
-20
-10
0
.
12
;
run;
data two;
set one;
if index(nub,'-') then delete;
run;
Thanks,
Shiva
You need not missing() to judge it .
data one;
input nub;
cards;
-20
-10
0
.
12
;
run;
data two;
set one;
if nub<0 and not missing(nub) then delete;
run;
Ksharp
How about:
data one;
input nub;
cards;
-20
-10
0
.
12
;
run;
data two;
set one;
if .<nub<0 then delete;
run;
As . is always less than any value.
Steve Denham
SteveDenham wrote:
As . is always less than any value.
Are you sure?
2360 data _null_;
2361 x = . min ._;
2362 put x=;
2363 run;
x=_
How about ". is always less than any value on the real line (-∞,∞)" ?
And I learned something new about the underscore--I always thought it to be a character only.
Thanks!
Steve Denham
It is a special missing value not character underscore.
So I would assume (mmmm danger), that the same would apply for .A .B thru to .Z--the numeric missing codes?
Steve Denham
The same what?
We're now out of sync. See Hai.Kuo's post with the link to the order of missing values. That clarifies everything, and should satisfy the OP's question.
Since I have almost no need to use the "coded" missing values, I made the mistake of thinking that .A thru .Z were the equivalent of ._ for ordering (i.e. "the same").
Learned a lot this morning.
Steve Denham
See, this is exactly the reason I would never want to miss your post. Thanks!
Haikuo
Using the information from following link to construct your comparison:
http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a000989180.htm
Haikuo
A-HA!
That was the link I was looking for this morning.
So the .A thru .Z missing values are GREATER THAN .
Thanks Hai.kuo!
Steve Denham
According to this link ._ is not special missing value. I have always called it a special missing value.
Try
if sign(variable) EQ -1 then delete ;
See
http://www.sascommunity.org/wiki/Numeric_transformations
spraynardz90 wrote:
Hi I am looking to delete any observation with a negative value...
Generally I use:
data x; set x; if variable<0 then delete; run;
However this deletes blank observations such as '.' along with any negative values.
Does anyone know how to delete only negative values?
Unfortunately the statement below doesn't work:
data x; set x; if variable=- then delete; run;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.