BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Deepti_virmani
Calcite | Level 5

 

 

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;

 

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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

2 REPLIES 2
Astounding
PROC Star

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 ...

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 2 replies
  • 13239 views
  • 0 likes
  • 3 in conversation