BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.

I have amount columns as below, few amount column is 0(Zero) values, and some are more than Zero. I do not want Zero values from amount column. proc contents as below.

# Variable Type Len Format Informat Label
5 amount Num 8 18.    

 

When I am using as below, still I see amount 0 is there in output and not deleting. May I know what I am missing here in condition. 

data want;

set have;

if amount=o then delete;

run;

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Your example code does not have a zero in it.  Instead it has a lowercase letter O.

Try using zero instead.

data want;
  set have;
  if amount=0 then delete;
run;

If that still show some values as zero then perhaps they are between -0.5 and 0.5 since you asked SAS to display the values as integers by attaching the display format of 18. to the variable.

Try using the ROUND() function to round the value to an integer before comparing it to zero.

data want;
  set have;
  if round(amount,1)=0 then delete;
run;

Or perhaps you should display the values with a different format so you can see if they have something other then zero there that you might want to keep?

proc freq data=have;
  tables amount ;
  format amount best18.;
run;

View solution in original post

3 REPLIES 3
Tom
Super User Tom
Super User

Your example code does not have a zero in it.  Instead it has a lowercase letter O.

Try using zero instead.

data want;
  set have;
  if amount=0 then delete;
run;

If that still show some values as zero then perhaps they are between -0.5 and 0.5 since you asked SAS to display the values as integers by attaching the display format of 18. to the variable.

Try using the ROUND() function to round the value to an integer before comparing it to zero.

data want;
  set have;
  if round(amount,1)=0 then delete;
run;

Or perhaps you should display the values with a different format so you can see if they have something other then zero there that you might want to keep?

proc freq data=have;
  tables amount ;
  format amount best18.;
run;
Kurt_Bremser
Super User

If this:

data want;
set have;
if amount=o then delete;
run;

is really your code, then the log will most probably tell you that variable o is uninitialized, unless o is also contained in dataset have.

kumarsandip975
Pyrite | Level 9

o was typo, I mean if amount=0 then delete; 

SAS Innovate 2025: Register Now

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!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 930 views
  • 1 like
  • 3 in conversation