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
Quartz | Level 8

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

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

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
  • 3 replies
  • 780 views
  • 1 like
  • 3 in conversation