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

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
Lapis Lazuli | Level 10
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 < "

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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