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
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.