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

Hi guys, 

how can I set to 0 all numbers in a column of a data-set that are negative?

 

Thank you in advance

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

How about

 

data have;
   do _N_ = 1 to 100;
      x = rand('integer', -10, 10);
      output;
   end;
run;

data have;
   modify have;
   x = max(x, 0);
run;

View solution in original post

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

How about

 

data have;
   do _N_ = 1 to 100;
      x = rand('integer', -10, 10);
      output;
   end;
run;

data have;
   modify have;
   x = max(x, 0);
run;
NewUsrStat
Pyrite | Level 9
Thank you! It works perfectly!
Astounding
PROC Star

If you have missing values for some numbers, should they also be set to zero?  I'm going to assume the answer is no, only re-set the negative numbers.

data want;
   set have;
   array nums {*} _numeric_;
   do _n_=1 to dim(nums);
      if .Z < nums{_n_} < 0 then nums{_n_} = 0;
   end;
run;

If the intent is to set missing values to zero as well, the program becomes even easier.  Just remove the characters ".Z < "

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

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