BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
csetzkorn
Lapis Lazuli | Level 10

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.

1 ACCEPTED SOLUTION

Accepted Solutions
gauthamk28
Obsidian | Level 7
If expression then do;
Executable statements;
End;
Else do;
Executable statements;
End;

View solution in original post

4 REPLIES 4
Reeza
Super User

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

 

See the examples in the documentation 🙂 

 

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

csetzkorn
Lapis Lazuli | Level 10
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.
Reeza
Super User

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';

 

 

 

 

gauthamk28
Obsidian | Level 7
If expression then do;
Executable statements;
End;
Else do;
Executable statements;
End;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1695 views
  • 2 likes
  • 3 in conversation