Desktop productivity for business analysts and programmers

If then else if statement not working

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

If then else if statement not working

 

 

WHATS WRONG WITH THIS IF THEN ELSE STaTEMENT ? It keeps throwing error

Data work.XX1;

26

27 set work.XX;

28

29 where INTRA_IND = 'N' ;

30

31 if MSG_ID = 'NO MSG'

32

33 then

34

35 RELATIONSHIP_ID = GLOBL_CUST_ID ;

36

37 RELATIONSHIP_NAME = CUS_NAME;

38

39 else

____

160

2 The SAS System 10:23 Thursday, May 11, 2017

ERROR 160-185: No matching IF-THEN clause.

40

41 RELATIONSHIP_ID = MSG_ID;

 


Accepted Solutions
Solution
‎05-11-2017 06:40 AM
Super User
Super User
Posts: 7,720

Re: If then else if statement not working

Its not syntactically correct, if/then else can only have one command between then and else, and no ;.  To do block of code between then and else you use do; and end;, per:

data work.xx1;
  set work.xx;
  where intra_ind='N';
  if msg_id='NO MSG' then do;
    relationship_id=globl_cust_id;
    relationship_name=cus_name;
  end;
  else do;
    ...
  end;
run;

View solution in original post


All Replies
Super User
Posts: 5,366

Re: If then else if statement not working

You need a slightly different syntax with multiple "then" results:

 

if MSG_ID = 'NO MSG' then do;

   RELATIONSHIP_ID = GLOBL_CUST_ID ;

   RELATIONSHIP_NAME = CUS_NAME;

end;

else ...

Solution
‎05-11-2017 06:40 AM
Super User
Super User
Posts: 7,720

Re: If then else if statement not working

Its not syntactically correct, if/then else can only have one command between then and else, and no ;.  To do block of code between then and else you use do; and end;, per:

data work.xx1;
  set work.xx;
  where intra_ind='N';
  if msg_id='NO MSG' then do;
    relationship_id=globl_cust_id;
    relationship_name=cus_name;
  end;
  else do;
    ...
  end;
run;
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 301 views
  • 0 likes
  • 3 in conversation