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

AI Navigator GIF.gif


Navigate AI governance with SAS tools for compliance and ethical AI practices. Try SAS Ai Navigator for free for the first six months.

Check it out on Microsoft Marketplace →

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
  • 1684 views
  • 1 like
  • 3 in conversation