Help using Base SAS procedures

Delete negative values ( NOT '.')

Accepted Solution Solved
Reply
Contributor
Posts: 60
Accepted Solution

Delete negative values ( NOT '.')

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;


Accepted Solutions
Solution
‎07-12-2012 04:45 AM
Super Contributor
Posts: 349

Re: Delete negative values ( NOT '.')

Posted in reply to spraynardz90

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

View solution in original post


All Replies
Solution
‎07-12-2012 04:45 AM
Super Contributor
Posts: 349

Re: Delete negative values ( NOT '.')

Posted in reply to spraynardz90

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

Super User
Posts: 10,020

Re: Delete negative values ( NOT '.')

Posted in reply to spraynardz90

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


					
				
			
			
				
			
			
			
			
			
			
			
		
Respected Advisor
Posts: 2,655

Re: Delete negative values ( NOT '.')

Posted in reply to spraynardz90

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

Respected Advisor
Posts: 3,799

Re: Delete negative values ( NOT '.')

Posted in reply to SteveDenham

SteveDenham wrote:

As . is always less than any value.

Are you sure?

2360  data _null_;

2361     x = . min ._;

2362     put x=;

2363     run;

x=_

Respected Advisor
Posts: 2,655

Re: Delete negative values ( NOT '.')

Posted in reply to data_null__

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

Respected Advisor
Posts: 3,799

Re: Delete negative values ( NOT '.')

Posted in reply to SteveDenham

It is a special missing value not character underscore.

Respected Advisor
Posts: 2,655

Re: Delete negative values ( NOT '.')

Posted in reply to data_null__

So I would assume (mmmm danger), that the same would apply for .A .B thru to .Z--the numeric missing codes?

Steve Denham

Respected Advisor
Posts: 3,799

Re: Delete negative values ( NOT '.')

Posted in reply to SteveDenham

The same what?

Respected Advisor
Posts: 2,655

Re: Delete negative values ( NOT '.')

Posted in reply to data_null__

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

Respected Advisor
Posts: 3,156

Re: Delete negative values ( NOT '.')

Posted in reply to data_null__

See, this is exactly the reason I would never want to miss your post. Thanks!

Haikuo

Respected Advisor
Posts: 3,156

Re: Delete negative values ( NOT '.')

Posted in reply to spraynardz90

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

Respected Advisor
Posts: 2,655

Re: Delete negative values ( NOT '.')

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

Respected Advisor
Posts: 3,799

Re: Delete negative values ( NOT '.')

According to this link ._ is not special missing value.  I have always called it a special missing value.

Regular Contributor
Posts: 184

Re: Delete negative values ( NOT '.')

Posted in reply to spraynardz90

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;

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 17 replies
  • 3220 views
  • 5 likes
  • 9 in conversation