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 2025: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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