DATA Step, Macro, Functions and more

several statements in if and else part

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 78
Accepted Solution

several statements in if and else part

I did numerous google seraches but could not find an answer. What is the syntax, if I have several statements in the if and the then part of an if the statement? This is some pseudo code:

 

if /*	some condition */ then 
do;
	/*	statements */
end; else 
do
	/*	statements */
end;

 

The if part is fine but I am not sure about the then part.


Accepted Solutions
Solution
‎05-13-2017 10:15 AM
Contributor
Posts: 21

Re: several statements in if and else part

If expression then do;
Executable statements;
End;
Else do;
Executable statements;
End;

View solution in original post


All Replies
Super User
Posts: 17,819

Re: several statements in if and else part

You're missing a semicolon after the second DO statement. 

 

See the examples in the documentation Smiley Happy 

 

http://support.sas.com/documentation/cdl/en/basess/68381/HTML/default/viewer.htm#p0pcj5ajwyngron1wls...

 

Google seems broken these days. Consider searching directly at either lexjansen.com, communities.sas.com or support.sas.com

Frequent Contributor
Posts: 78

Re: several statements in if and else part

Thanks I found the link you provided via google but it did not show what I was after (e.g. not using else if). gauthamk28 provided what I was after. Thanks anyway.
Super User
Posts: 17,819

Re: several statements in if and else part

This one has a fourth example that is interesting, I wouldn't have expected that to work. 

 

http://support.sas.com/documentation/cdl/en/lestmtsref/69738/HTML/default/viewer.htm#n1j60arf27ll4nn...

 

if x=0 then  
   if y ne 0 then put 'X ZERO, Y NONZERO'; 
   else put 'X ZERO, Y ZERO';
else put 'X NONZERO';

 

 

 

 

Solution
‎05-13-2017 10:15 AM
Contributor
Posts: 21

Re: several statements in if and else part

If expression then do;
Executable statements;
End;
Else do;
Executable statements;
End;
☑ This topic is SOLVED.

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

Discussion stats
  • 4 replies
  • 144 views
  • 2 likes
  • 3 in conversation