Then this should work:
data have;
input flg :$1. in_flow :$3. out_flow :$3. value $;
datalines;
N OUT XX 1
N XX IN 2
Y OUT XX 3
Y XX IN 4
X X X 5
;
proc sql;
create table want as
select
have.*,
CASE
WHEN FLG = 'N' and UPCASE (IN_FLOW) = 'OUT' THEN (input(VALUE, BEST32.) * (-1))
when FLG = 'Y' and UPCASE (OUT_FLOW) = 'IN' THEN (input(VALUE, BEST32.) * (-1))
ELSE (input(VALUE, BEST32.))
END as AMT
from have;
quit;
Note that, in the CASE clause, every THEN needs a WHEN.
Here's an equivalent alternative definition of AMT:
(-1)**(flg='N' & upcase(in_flow)='OUT' | flg='Y' & upcase(out_flow)='IN')*input(value,32.) as AMT
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.