BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
spraynardz90
Calcite | Level 5

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;

1 ACCEPTED SOLUTION

Accepted Solutions
shivas
Pyrite | Level 9

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

17 REPLIES 17
shivas
Pyrite | Level 9

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

Ksharp
Super User

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


					
				
			
			
				
			
			
			
			
			
			
			
		
SteveDenham
Jade | Level 19

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

data_null__
Jade | Level 19

SteveDenham wrote:

As . is always less than any value.

Are you sure?

2360  data _null_;

2361     x = . min ._;

2362     put x=;

2363     run;

x=_

SteveDenham
Jade | Level 19

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

data_null__
Jade | Level 19

It is a special missing value not character underscore.

SteveDenham
Jade | Level 19

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

Steve Denham

data_null__
Jade | Level 19

The same what?

SteveDenham
Jade | Level 19

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

Haikuo
Onyx | Level 15

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

Haikuo

Haikuo
Onyx | Level 15

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

SteveDenham
Jade | Level 19

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

data_null__
Jade | Level 19

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

Howles
Quartz | Level 8

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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 17 replies
  • 8445 views
  • 6 likes
  • 9 in conversation