DATA Step, Macro, Functions and more

Delete "zero rows"

Reply
Contributor
Posts: 33

Delete "zero rows"

Hi,

 

 

i have dataset from which i want to delete Entire ROWS WHich columns contails following values.(zero, zeros with decimal point & Dot)

 

 

0   -: zero

 

0.000  -: Zeros with decimal

.    -: Dot

 

can i have solution on this? thank you

Super User
Super User
Posts: 7,407

Re: Delete "zero rows"

Then you would use if, where, select or any other conditional statements:

data want;

  set have;

  if <variable> in (.,0) then delete;  /* Assuming numeric  */

  if <variable> in (".","0","0.000") then delete;  /* Assuming character */

run;

 

Or:

data want;

  set have (where=(<variable> not in (.,0) or <variable> not in (".","0","0.000")));

run;

Contributor
Posts: 39

Re: Delete "zero rows"

If the variable is numeric, you may want to round the value, especially if it is the result of a computation.  Sometimes floating point caculations result in values so close to zero, that you want to treat them as zero.

Super User
Posts: 5,085

Re: Delete "zero rows"

You say you have a data set ... but is it already a SAS data set?  (It would be extremely unusual for a variable to contain "0.000" in a SAS data set, but it is possible.)

 

Are you looking to apply these conditions to character variables as well?  What if the character variable is merely blank and doesn't contain a dot?

 

 

Respected Advisor
Posts: 3,777

Re: Delete "zero rows"

[ Edited ]

Astounding wrote:

You say you have a data set ... but is it already a SAS data set?  (It would be extremely unusual for a variable to contain "0.000" in a SAS data set, but it is possible.)

 

 


That's mostly right  zero is zero but it can be made to appear as 0.000

 

40         data _null_;
41            x = 0;
42            put x=f5.3;
43            run;

x=0.000

 

Trusted Advisor
Posts: 1,115

Re: Delete "zero rows"

Formatted values can also conceal the true values. So, "0.000" could in fact be 0.000456 (or, in the worst case, something completely different, depending on the format definition).

 

Another potential issue: If you are dealing with numeric values which have been converted to character values, there is a high probability of leading blanks.

 

Please see the examples below:

data have;
do x=., 0, 0.000456; /* numeric */
  xf=x;              /* numeric, formatted (see FORMAT statement) */
  t=put(x, 6.3);     /* character */
  c='#'||t||'#';     /* just to make blanks visible */
  output;
end;
format xf 6.3;
proc print;
run;

data want;
set have;
if x | xf | input(t, 30.);
run;

A numeric value can be used as an IF condition: It is evaluated as true if and only if it is neither zero nor missing.

 

 

Super User
Posts: 9,682

Re: Delete "zero rows"


data have;
input x $20.;
if missing(x) then x=.;
cards;
0
00
0.
0.00
0.000
.
..
12
;
run;
data want;
 set have;
 if prxmatch('/^0+$|^0+\.0*$|^\.+$/',strip(x)) then delete;
run;
Contributor
Posts: 33

Re: Delete "zero rows"

 so much all of your efforts

 

 

 

issue is resolved now

Contributor
Posts: 33

Re: Delete "zero rows"

thank u so much

Ask a Question
Discussion stats
  • 8 replies
  • 316 views
  • 0 likes
  • 7 in conversation