BookmarkSubscribeRSS Feed
David_Billa
Rhodochrosite | Level 12
 
4 REPLIES 4
David_Billa
Rhodochrosite | Level 12
Character
Kurt_Bremser
Super User

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.

FreelanceReinh
Jade | Level 19

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

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

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!

Register now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 913 views
  • 1 like
  • 3 in conversation