☑ This topic is solved.
Need further help from the community? Please
sign in and ask a new question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 08-09-2022 08:36 AM
(2864 views)
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you! It works perfectly!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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 < "