<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: nested if-then/else grouping in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/nested-if-then-else-grouping/m-p/50239#M13683</link>
    <description>Your attempts to use nested/stacked IF / THEN without using an associated DO/END  is causing your code path to fail.  Suggest you simplify your code by using complete DO/END structure for all code paths, even if only one line of code.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
    <pubDate>Fri, 16 Jul 2010 04:18:03 GMT</pubDate>
    <dc:creator>sbb</dc:creator>
    <dc:date>2010-07-16T04:18:03Z</dc:date>
    <item>
      <title>nested if-then/else grouping</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/nested-if-then-else-grouping/m-p/50234#M13678</link>
      <description>Hello,&lt;BR /&gt;
I've got the following if-then/else data grouping.  &lt;BR /&gt;
&lt;BR /&gt;
[&lt;BR /&gt;
 if Runner3BId=0 then&lt;BR /&gt;
 _if Runner2BId=0 then&lt;BR /&gt;
 ___if Runner1BId=0 then do;&lt;BR /&gt;
_______baserunners = 0; 		/*bases empty*/&lt;BR /&gt;
_________end;&lt;BR /&gt;
_______else do; baserunners = 1; 	/*man on 1b*/&lt;BR /&gt;
_______end;&lt;BR /&gt;
__else if Runner2BId ^= 0 then do;&lt;BR /&gt;
____yada, yada&lt;BR /&gt;
  end;&lt;BR /&gt;
]  this part works fine and assigns the baserunners variable correctly&lt;BR /&gt;
&lt;BR /&gt;
but the second half of the Runner3BId has the correct nesting structure but doesn't assign the variable.  so the problem has to be in the first 2 line here (i think) but for the life of me, i can't see what is wrong.&lt;BR /&gt;
[&lt;BR /&gt;
_else if Runner3BId ^= 0 then do;&lt;BR /&gt;
__if Runner2BId=0 then&lt;BR /&gt;
_____if Runner1BId=0 then do;&lt;BR /&gt;
________baserunners = 3;		/*man on 3b*/ &lt;BR /&gt;
________end;&lt;BR /&gt;
_____else do; baserunners = 5; /*men on 1b&amp;amp;3b*/&lt;BR /&gt;
_____end;&lt;BR /&gt;
__else if Runner2BId ^= 0 then do;	&lt;BR /&gt;
    yada, yada&lt;BR /&gt;
__end;&lt;BR /&gt;
_end;&lt;BR /&gt;
run;&lt;BR /&gt;
]  &lt;BR /&gt;
&lt;BR /&gt;
Anyone see what i'm doing wrong?&lt;BR /&gt;
&lt;BR /&gt;
damn it, why don't they allow the leading spaces on the lines?  let's try underscore

Message was edited by: CharlesR</description>
      <pubDate>Thu, 15 Jul 2010 03:56:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/nested-if-then-else-grouping/m-p/50234#M13678</guid>
      <dc:creator>CharlesR</dc:creator>
      <dc:date>2010-07-15T03:56:46Z</dc:date>
    </item>
    <item>
      <title>Re: nested if-then/else grouping</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/nested-if-then-else-grouping/m-p/50235#M13679</link>
      <description>It is very hard to read your code and understand if-then logic there. One thing – maybe instead of &lt;BR /&gt;
&lt;BR /&gt;
if Runner2BId=0 then&lt;BR /&gt;
if Runner1BId=0 then do;&lt;BR /&gt;
&lt;BR /&gt;
 you should write &lt;BR /&gt;
&lt;BR /&gt;
if Runner2BId=0 and&lt;BR /&gt;
if Runner1BId=0 then do;&lt;BR /&gt;
&lt;BR /&gt;
And maybe you should check the logic of the code – where does do-end start and end, maybe code is skipping some important part.&lt;BR /&gt;
&lt;BR /&gt;
Good luck in fixing your code!</description>
      <pubDate>Thu, 15 Jul 2010 07:00:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/nested-if-then-else-grouping/m-p/50235#M13679</guid>
      <dc:creator>ieva</dc:creator>
      <dc:date>2010-07-15T07:00:40Z</dc:date>
    </item>
    <item>
      <title>Re: nested if-then/else grouping</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/nested-if-then-else-grouping/m-p/50236#M13680</link>
      <description>also the sequencing of if-then statement.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
if 'condition1' then do ; .... end;&lt;BR /&gt;
else if 'condition2' then do ; .... end;&lt;BR /&gt;
else if 'condition3' then do ; .... end;&lt;BR /&gt;
.&lt;BR /&gt;
.&lt;BR /&gt;
.&lt;BR /&gt;
.&lt;BR /&gt;
else do; .... end;</description>
      <pubDate>Thu, 15 Jul 2010 14:19:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/nested-if-then-else-grouping/m-p/50236#M13680</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-07-15T14:19:41Z</dc:date>
    </item>
    <item>
      <title>Re: nested if-then/else grouping</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/nested-if-then-else-grouping/m-p/50237#M13681</link>
      <description>Also, for diagnosing your own SAS program, consider using PUTLOG _ALL_;  and/or issue a PUTLOG command with a unique text-message in one or more of your DO/END code paragraphs.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Thu, 15 Jul 2010 14:28:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/nested-if-then-else-grouping/m-p/50237#M13681</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-07-15T14:28:13Z</dc:date>
    </item>
    <item>
      <title>Re: nested if-then/else grouping</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/nested-if-then-else-grouping/m-p/50238#M13682</link>
      <description>i thought about a simple &lt;ELSE do=""&gt; &lt;BR /&gt;
but it also didn't work.&lt;/ELSE&gt;</description>
      <pubDate>Fri, 16 Jul 2010 03:15:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/nested-if-then-else-grouping/m-p/50238#M13682</guid>
      <dc:creator>CharlesR</dc:creator>
      <dc:date>2010-07-16T03:15:21Z</dc:date>
    </item>
    <item>
      <title>Re: nested if-then/else grouping</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/nested-if-then-else-grouping/m-p/50239#M13683</link>
      <description>Your attempts to use nested/stacked IF / THEN without using an associated DO/END  is causing your code path to fail.  Suggest you simplify your code by using complete DO/END structure for all code paths, even if only one line of code.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Fri, 16 Jul 2010 04:18:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/nested-if-then-else-grouping/m-p/50239#M13683</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-07-16T04:18:03Z</dc:date>
    </item>
    <item>
      <title>Re: nested if-then/else grouping</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/nested-if-then-else-grouping/m-p/50240#M13684</link>
      <description>I'm not sure i totally understand what you're saying.  i'd like to think that i understand, but, i'd be wrong, lol.&lt;BR /&gt;
&lt;BR /&gt;
what is an associated DO/END?  specifically, how is it different from what i have done so far?</description>
      <pubDate>Fri, 16 Jul 2010 04:25:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/nested-if-then-else-grouping/m-p/50240#M13684</guid>
      <dc:creator>CharlesR</dc:creator>
      <dc:date>2010-07-16T04:25:15Z</dc:date>
    </item>
    <item>
      <title>Re: nested if-then/else grouping</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/nested-if-then-else-grouping/m-p/50241#M13685</link>
      <description>You have a hierarchy of IF &lt;CONDITION&gt; THEN &lt;ACTION&gt;;  and attempting to use that structure also with nested ELSE/DO/END and/or ELSE IF &lt;CONDITION&gt; THEN &lt;ACTION&gt;  code paragraphs, intermixed.  Because of your coding technique, those nested logic paths may or may not fire (based on your &lt;CONDITION&gt; logic) and by using DO/END for each of the nested code path conditions, you will see more predictable code execution.  Also, for your own debugging, by using the DO/END logic, you can then insert PUTLOG commands to more easily test all logic paths, where messages get echo'd to the SASLOG.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;/CONDITION&gt;&lt;/ACTION&gt;&lt;/CONDITION&gt;&lt;/ACTION&gt;&lt;/CONDITION&gt;</description>
      <pubDate>Fri, 16 Jul 2010 12:54:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/nested-if-then-else-grouping/m-p/50241#M13685</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-07-16T12:54:09Z</dc:date>
    </item>
    <item>
      <title>Re: nested if-then/else grouping</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/nested-if-then-else-grouping/m-p/50242#M13686</link>
      <description>Ah.  I'm quite new to SAS and was somehow under the impression that my IF/THEN loop had to have the DO statement in order to work.  &lt;BR /&gt;
&lt;BR /&gt;
So i can essentially write a series of DO loops which will assign the values correctly.  I would then assume i have to have the data sorted appropriately, meaning sorted by Runner3BId, Runner2BId, Runner1BId.  i could essentially have something like this:&lt;BR /&gt;
&lt;BR /&gt;
do until(EndoFile);&lt;BR /&gt;
__do until Runner3BId ^= 0;&lt;BR /&gt;
___do until Runner2BId ^= 0&lt;BR /&gt;
_____do until Runner1BId ^= 0;&lt;BR /&gt;
_______baserunners = 0; /*bases empty*/&lt;BR /&gt;
_____END;&lt;BR /&gt;
_____baserunners = 1; /*man on 1st*/&lt;BR /&gt;
___END;&lt;BR /&gt;
&lt;BR /&gt;
etc. etc.</description>
      <pubDate>Fri, 16 Jul 2010 14:26:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/nested-if-then-else-grouping/m-p/50242#M13686</guid>
      <dc:creator>CharlesR</dc:creator>
      <dc:date>2010-07-16T14:26:20Z</dc:date>
    </item>
    <item>
      <title>Re: nested if-then/else grouping</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/nested-if-then-else-grouping/m-p/50243#M13687</link>
      <description>Uhhh, you're going to need a SET statement somewhere inside the outer DO/END loop, and I suggest exploring the use of LEAVE and CONTINUE, as well, depending on your circumstances.  Also, the STOP;  statement possibly for premature DATA-step termination.&lt;BR /&gt;
&lt;BR /&gt;
Although, you also need to understand about SAS DATA step pass behavior when running a DO/END with an interior SET statement -- effectively you only execute one DATA step pass (depends on the application rqmt though).&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;BR /&gt;
&lt;BR /&gt;
Suggested Google advanced search argument, this topic / post:&lt;BR /&gt;
&lt;BR /&gt;
data step programming intro site:sas.com</description>
      <pubDate>Fri, 16 Jul 2010 14:35:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/nested-if-then-else-grouping/m-p/50243#M13687</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-07-16T14:35:37Z</dc:date>
    </item>
    <item>
      <title>Re: nested if-then/else grouping</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/nested-if-then-else-grouping/m-p/50244#M13688</link>
      <description>CharlesR&lt;BR /&gt;
 &lt;BR /&gt;
although you are new to SAS you may not be new to such IF/THEN logic.&lt;BR /&gt;
To watch the data step flow, I would really recommend using  the data step option /DEBUG ; [pre]data output_data_set /debug ;&lt;BR /&gt;
  do whatever ;&lt;BR /&gt;
     if   whatever ........ ;&lt;BR /&gt;
  end ;&lt;BR /&gt;
run ;[/pre]&lt;BR /&gt;
Debugger will let you step through your code and examine variable values - but does not work in  SAS Enterprise Guide - yet.&lt;BR /&gt;
 &lt;BR /&gt;
good luck&lt;BR /&gt;
peterC</description>
      <pubDate>Fri, 16 Jul 2010 14:41:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/nested-if-then-else-grouping/m-p/50244#M13688</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2010-07-16T14:41:28Z</dc:date>
    </item>
    <item>
      <title>Re: nested if-then/else grouping</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/nested-if-then-else-grouping/m-p/50245#M13689</link>
      <description>i am doing this all under data, so it begins with&lt;BR /&gt;
&lt;BR /&gt;
data testdata;&lt;BR /&gt;
__set testdata;&lt;BR /&gt;
&lt;BR /&gt;
then goes into the do loop.  &lt;BR /&gt;
&lt;BR /&gt;
as for leave and continue, the problem with them is that they will exit the loop correct?    i note how you say depending on the circumstances, the biggest problem is that i'm not sure how to incorporate them when i want the loop to cycle through all the data.&lt;BR /&gt;
&lt;BR /&gt;
also, how can i sort the data in a binary fashion?  i.e. i want it to sort by Runner3BId as to whether it = 0 or is &amp;gt; 0, then within that as to whether Runner2BID is = 0 or &amp;gt;0 and then the same with Runner1BId, as opposed to everything running numerically.  Am i better off simply creating a new variable which simply indicate whether there is someone on 1st, 2nd and/or 3rd?</description>
      <pubDate>Fri, 16 Jul 2010 17:18:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/nested-if-then-else-grouping/m-p/50245#M13689</guid>
      <dc:creator>CharlesR</dc:creator>
      <dc:date>2010-07-16T17:18:52Z</dc:date>
    </item>
    <item>
      <title>Re: nested if-then/else grouping</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/nested-if-then-else-grouping/m-p/50246#M13690</link>
      <description>Numeric variables yield a binary sort or if you are more concerned, yes, detect some condition and set a 1 or 0, and sort on that as a BY variable.&lt;BR /&gt;
&lt;BR /&gt;
And, so, if you do not want to exit a DO/END loop, use some combination of variables in an expression, to get you into the loop and then set a flag-variable to get you out.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Fri, 16 Jul 2010 17:29:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/nested-if-then-else-grouping/m-p/50246#M13690</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-07-16T17:29:13Z</dc:date>
    </item>
    <item>
      <title>Re: nested if-then/else grouping</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/nested-if-then-else-grouping/m-p/50247#M13691</link>
      <description>Where can i find how to do a binary sort with numeric values?  Tried to google it, but not sure where to look exactly . . .</description>
      <pubDate>Fri, 16 Jul 2010 19:15:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/nested-if-then-else-grouping/m-p/50247#M13691</guid>
      <dc:creator>CharlesR</dc:creator>
      <dc:date>2010-07-16T19:15:17Z</dc:date>
    </item>
    <item>
      <title>Re: nested if-then/else grouping</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/nested-if-then-else-grouping/m-p/50248#M13692</link>
      <description>Honestly, you should open a new forum thread...&lt;BR /&gt;
&lt;BR /&gt;
Start here with basic SAS PROC SORT documentation, then review the particulars for your OS with the SAS Companion guide.&lt;BR /&gt;
&lt;BR /&gt;
Google advanced search argument, this topic / post:&lt;BR /&gt;
&lt;BR /&gt;
proc sort documentation site:sas.com&lt;BR /&gt;
&lt;BR /&gt;
proc sort numeric variables binary collation site:sas.com&lt;BR /&gt;
&lt;BR /&gt;
numeric variables binary collation sort site:sas.com&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.

Message was edited by: sbb</description>
      <pubDate>Fri, 16 Jul 2010 19:36:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/nested-if-then-else-grouping/m-p/50248#M13692</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-07-16T19:36:26Z</dc:date>
    </item>
    <item>
      <title>Re: nested if-then/else grouping</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/nested-if-then-else-grouping/m-p/50249#M13693</link>
      <description>I'm responding to this statement:&lt;BR /&gt;
&lt;B&gt;&lt;I&gt;&lt;BR /&gt;
Ah. I'm quite new to SAS and was somehow under the impression that my IF/THEN loop had to have the DO statement in order to work. &lt;BR /&gt;
&lt;/I&gt;&lt;/B&gt;&lt;I&gt;&lt;/I&gt;&lt;BR /&gt;
 &lt;BR /&gt;
Here's the deal....Let's start with a simple IF statement and a simple IF/ELSE:&lt;BR /&gt;
[pre]&lt;BR /&gt;
if wombat = 'true' then &lt;B&gt;&lt;I&gt;&amp;lt; put 1 and only 1 statement here &amp;gt;&lt;/I&gt;&lt;/B&gt;&lt;I&gt;&lt;/I&gt; ;&lt;BR /&gt;
       &lt;BR /&gt;
OR&lt;BR /&gt;
                  &lt;BR /&gt;
if wombat = 'true' then &lt;B&gt;&lt;I&gt;&amp;lt; put 1 and only 1 statement here &amp;gt; &lt;/I&gt;&lt;/B&gt;&lt;I&gt;&lt;/I&gt;;&lt;BR /&gt;
else &lt;B&gt;&lt;I&gt; &amp;lt; put a single statement here &amp;gt;&lt;/I&gt;&lt;/B&gt;&lt;I&gt;&lt;/I&gt; ;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
 &lt;BR /&gt;
The very nanosecond that you say to yourself...oh gosh, I need to have 2 or 3 statements get executed if wombat = 'true' then you are into the world of the DO/END block (or as we used to say in my programming class -- the structured IF/DO/END):&lt;BR /&gt;
[pre]&lt;BR /&gt;
if wombat = 'true' then do;&lt;BR /&gt;
   &lt;B&gt;&lt;I&gt;&amp;lt; put 1 statement here &amp;gt; &lt;/I&gt;&lt;/B&gt;&lt;I&gt;&lt;/I&gt;;&lt;BR /&gt;
   &lt;B&gt;&lt;I&gt;&amp;lt; put statement 2 here &amp;gt; &lt;/I&gt;&lt;/B&gt;&lt;I&gt;&lt;/I&gt;;&lt;BR /&gt;
   &lt;B&gt;&lt;I&gt;&amp;lt; put statement 3 here &amp;gt; &lt;/I&gt;&lt;/B&gt;&lt;I&gt;&lt;/I&gt;;&lt;BR /&gt;
end;&lt;BR /&gt;
       &lt;BR /&gt;
OR&lt;BR /&gt;
&lt;BR /&gt;
if wombat = 'true' then do;&lt;BR /&gt;
   &lt;B&gt;&lt;I&gt;&amp;lt; put 1 statement here &amp;gt; &lt;/I&gt;&lt;/B&gt;&lt;I&gt;&lt;/I&gt; ;&lt;BR /&gt;
   &lt;B&gt;&lt;I&gt;&amp;lt; put statement 2 here &amp;gt; &lt;/I&gt;&lt;/B&gt;&lt;I&gt;&lt;/I&gt;;&lt;BR /&gt;
   &lt;B&gt;&lt;I&gt;&amp;lt; put statement 3 here &amp;gt; &lt;/I&gt;&lt;/B&gt;&lt;I&gt;&lt;/I&gt; ;&lt;BR /&gt;
end;&lt;BR /&gt;
else do;&lt;BR /&gt;
   &lt;B&gt;&lt;I&gt;&amp;lt; put diff statement 1 here &amp;gt;&lt;/I&gt;&lt;/B&gt;&lt;I&gt;&lt;/I&gt; ;&lt;BR /&gt;
   &lt;B&gt;&lt;I&gt;&amp;lt; put diff statement 2 here &amp;gt;&lt;/I&gt;&lt;/B&gt;&lt;I&gt;&lt;/I&gt; ;&lt;BR /&gt;
   &lt;B&gt;&lt;I&gt;&amp;lt; put diff statement 3 here &amp;gt;&lt;/I&gt;&lt;/B&gt;&lt;I&gt;&lt;/I&gt; ;&lt;BR /&gt;
end;&lt;BR /&gt;
          &lt;BR /&gt;
OR, even -- transmute the simple IF to an IF/DO/END:&lt;BR /&gt;
          &lt;BR /&gt;
if wombat = 'true' then do;&lt;BR /&gt;
   &lt;B&gt;&lt;I&gt;&amp;lt; put 1 and only 1 statement here &amp;gt; &lt;/I&gt;&lt;/B&gt;&lt;I&gt;&lt;/I&gt;;&lt;BR /&gt;
end;&lt;BR /&gt;
else do;&lt;BR /&gt;
  &lt;B&gt;&lt;I&gt;&amp;lt; put a single statement here &amp;gt; &lt;/I&gt;&lt;/B&gt;&lt;I&gt;&lt;/I&gt;;&lt;BR /&gt;
end;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
                              &lt;BR /&gt;
In fact, my SAS mentor was something of a curmudgeon about NOT using the simple form of the IF statement -- on the a theory that if you used the IF/DO/END construction, even when you only needed to execute 1 statement on the true and another single statement on the false -- it would be easier for you maintenance-wise and in the long run (when you had to modify the code to add more statements) to just have the DO/END used all the time. Then it was easy to document:&lt;BR /&gt;
[pre]&lt;BR /&gt;
if wombat = 'true' then do;  /* when wombat is true, set foobar to 1 */&lt;BR /&gt;
   &amp;lt; put 1 and only 1 statement here &amp;gt; ;&lt;BR /&gt;
end;                         /* end wombat true */&lt;BR /&gt;
else do;                     /* when wombat is false, set foobar to 0 */&lt;BR /&gt;
  &amp;lt; put a single statement here &amp;gt; ;&lt;BR /&gt;
end;                         /* end wombat false */&lt;BR /&gt;
[/pre]   &lt;BR /&gt;
                                   &lt;BR /&gt;
Now that may seem overkill in the documentation department but consider the nested DO possibilities:&lt;BR /&gt;
[pre]&lt;BR /&gt;
if wombat = 'true' then do;   /* when wombat is true, set foobar to 1 */&lt;BR /&gt;
   &amp;lt; put 1 and only 1 statement here &amp;gt; ;&lt;BR /&gt;
   if character = 'kermit' and street = 'sesame' then do;  /* kermit test */&lt;BR /&gt;
      &amp;lt; put 1 statement here &amp;gt; ;&lt;BR /&gt;
      &amp;lt; put statement 2 here &amp;gt; ;&lt;BR /&gt;
   end;                                                    /* end for kermit test */&lt;BR /&gt;
end;                        /* end wombat true */&lt;BR /&gt;
else do;  /* when wombat is false, set foobar to 0  and test character and hat*/&lt;BR /&gt;
  &amp;lt; put a statement here &amp;gt; ;&lt;BR /&gt;
  if character = 'tom terrific' and hat = 'pointed' then do; /* tt and hat test */&lt;BR /&gt;
      &amp;lt; put 1 statement here &amp;gt; ;&lt;BR /&gt;
      &amp;lt; put statement 2 here &amp;gt; ;&lt;BR /&gt;
  end;                                                       /* end tom terrific and hat test */&lt;BR /&gt;
  else do;  /* do not care about any other character */&lt;BR /&gt;
      &amp;lt; put a statement here &amp;gt; ;&lt;BR /&gt;
  end;      /* end for tom terrific when wombat is false */ &lt;BR /&gt;
end;      /* end wombat false */&lt;BR /&gt;
[/pre]   &lt;BR /&gt;
                      &lt;BR /&gt;
and I know that there have wars fought over how the IF, THEN, DO and END should be indented and on which line the DO should appear...but I like to see a semi-colon at the end of each line and I like to have the ENDs line up with the IFs and the DO at the end of the THEN. But that's just me.&lt;BR /&gt;
                &lt;BR /&gt;
Without getting into the world of LOOPS, that's a somewhat artificial explanation of how IF statements work in SAS. You don't NEED to have a DO/END if you are only going to execute 1 statement, but you DO need to have a DO/END if you need to have 2 or more statements executed.&lt;BR /&gt;
&lt;BR /&gt;
I now always follow the DO/END recommendation of my mentor, even if for 1 statement scenario....more often than not, I do go back and add more statements and thinking about the conditions and the DO/END, makes me clarify my logic. And for really, really complicated logic, I haul out my flowchart ruler and draw it out. Sometimes, the picture makes the coding easier.&lt;BR /&gt;
&lt;BR /&gt;
my .02,&lt;BR /&gt;
                 &lt;BR /&gt;
cynthia</description>
      <pubDate>Fri, 16 Jul 2010 23:54:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/nested-if-then-else-grouping/m-p/50249#M13693</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2010-07-16T23:54:26Z</dc:date>
    </item>
    <item>
      <title>Re: nested if-then/else grouping</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/nested-if-then-else-grouping/m-p/50250#M13694</link>
      <description>Yep, you're right.  I was trying to get all "fancy" by having the nested loops/do end statements, and i needed to break it down to my 8 permutations with 8 if/else if's.  More straight forward this way.&lt;BR /&gt;
&lt;BR /&gt;
Thanks!</description>
      <pubDate>Sat, 17 Jul 2010 23:41:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/nested-if-then-else-grouping/m-p/50250#M13694</guid>
      <dc:creator>CharlesR</dc:creator>
      <dc:date>2010-07-17T23:41:01Z</dc:date>
    </item>
    <item>
      <title>Re: nested if-then/else grouping</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/nested-if-then-else-grouping/m-p/50251#M13695</link>
      <description>hey thanks for all your help!!</description>
      <pubDate>Sat, 17 Jul 2010 23:41:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/nested-if-then-else-grouping/m-p/50251#M13695</guid>
      <dc:creator>CharlesR</dc:creator>
      <dc:date>2010-07-17T23:41:31Z</dc:date>
    </item>
  </channel>
</rss>

