Hi,
I need a statement to show
if balance is a minus number then 0.
How is this written please?
Hi,
data want;
set have;
if value < 0 then result=0;
else result=1;
run;
result is 0 for minus numbers, 1 otherwise.
Hi RW9,
Sorry, can i have this in proc sql please?
Hello,
PROC SQL;
select *,
case when age-13 lt 0 then 0
else age-13
end as age_diff from sashelp.class;
quit;
Replace if /then with case/when
case when <condition> then <result> else <default option> end as variable
Can also be
case <variable> when <condition> then <result> else <default option> end
E.g.
case when variable < 0 then 0 else 1 as result
Another approach is to not change the value just how it displays with a custom format:
proc format;
value myneg
low - 0 = 0
other = [best8.]
;
And in any display use that format by adding
Format var myneg. ;
Hi ... another way in SQL ...
data old;
input balance @@;
datalines;
-1 20 56 -99 . 80 100 -0.123
;
proc sql;
select *, balance - (balance lt 0) * balance as new from old;
quit;
balance new
---------------------------------
-1 0
20 20
56 56
-99 0
. .
80 80
100 100
-0.123 0
though if it's just display that's important, the suggestion about using a FORMAT is probably better
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!
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.