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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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