<?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: Error in a DO loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Error-in-a-DO-loop/m-p/916566#M360998</link>
    <description>&lt;P&gt;Thanks for your help!&lt;/P&gt;</description>
    <pubDate>Fri, 16 Feb 2024 19:59:38 GMT</pubDate>
    <dc:creator>newtriks</dc:creator>
    <dc:date>2024-02-16T19:59:38Z</dc:date>
    <item>
      <title>Error in a DO loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-in-a-DO-loop/m-p/916521#M360992</link>
      <description>&lt;P&gt;I wrote the code below to consolidate mutually-exclusive variables into 2 "catch-all" variables, but the only line that's copying correctly is the one outside of the DO loop. What am I missing? I appreciate any and all help - thanks.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;IF Q_4_1_1 NE . THEN DO;&lt;BR /&gt;ChatGPT41 = Q_4_1_1; ChatGPT42 = Q_4_1_2; ChatGPT43 = Q_4_1_3; ChatGPT5 = Q_5_1; ChatGPT6 = Q_6_1; ChatGPT7 = Q_7_1;&lt;BR /&gt;END;&lt;BR /&gt;IF Q_4_2_1 NE . THEN DO;&lt;/P&gt;
&lt;P&gt;ChatGPT41 = Q_4_2_1; ChatGPT42 = Q_4_2_2; ChatGPT43 = Q_4_2_3; ChatGPT5 = Q_5_2; ChatGPT6 = Q_6_2; ChatGPT7 = Q_7_2;&lt;BR /&gt;END;&lt;BR /&gt;IF Q_4_3_1 NE . THEN DO;&lt;BR /&gt;ChatGPT41 = Q_4_3_1; ChatGPT42 = Q_4_3_2; ChatGPT43 = Q_4_3_3; ChatGPT5 = Q_5_3; ChatGPT6 = Q_6_3; ChatGPT7 = Q_7_3;&lt;BR /&gt;END;&lt;BR /&gt;IF Q_4_4_1 NE . THEN DO;&lt;BR /&gt;ChatGPT41 = Q_4_4_1; ChatGPT42 = Q_4_4_2; ChatGPT43 = Q_4_4_3; ChatGPT5 = Q_5_4; ChatGPT6 = Q_6_4; ChatGPT7 = Q_7_4;&lt;BR /&gt;END;&lt;BR /&gt;ELSE ChatGPT41 = Q_4_5_1; ChatGPT42 = Q_4_5_2; ChatGPT43 = Q_4_5_3; ChatGPT5 = Q_5_5; ChatGPT6 = Q_6_5; ChatGPT7 = Q_7_5;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Feb 2024 18:02:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-in-a-DO-loop/m-p/916521#M360992</guid>
      <dc:creator>newtriks</dc:creator>
      <dc:date>2024-02-16T18:02:57Z</dc:date>
    </item>
    <item>
      <title>Re: Error in a DO loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-in-a-DO-loop/m-p/916526#M360994</link>
      <description>&lt;P&gt;ELSE is part of the immediately preceding IF.&lt;/P&gt;
&lt;P&gt;To build a chain of mutually exclusive branches, you need to use&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if /* condition 1 */
then /* branch 1 */;
else if /* condition 2 */
then /* branch 2 */;
else if /* condition 3 */
then /* branch 3 */;
else /* global else branch */;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 16 Feb 2024 18:21:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-in-a-DO-loop/m-p/916526#M360994</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-02-16T18:21:37Z</dc:date>
    </item>
    <item>
      <title>Re: Error in a DO loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-in-a-DO-loop/m-p/916527#M360995</link>
      <description>&lt;P&gt;And you have no DO&amp;nbsp;&lt;U&gt;loop&lt;/U&gt; here, only several DO/END blocks. "Loop" is used for repeating DO uses, like&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do x = 1 to 5,
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(iterative)&lt;/P&gt;
&lt;P&gt;or DO WHILE (condition)&lt;/P&gt;
&lt;P&gt;or DO UNTIL (condition)&lt;/P&gt;</description>
      <pubDate>Fri, 16 Feb 2024 18:27:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-in-a-DO-loop/m-p/916527#M360995</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-02-16T18:27:05Z</dc:date>
    </item>
    <item>
      <title>Re: Error in a DO loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-in-a-DO-loop/m-p/916529#M360996</link>
      <description>&lt;P&gt;As a minimum on suspects that your ELSE is improperly structured.&lt;/P&gt;
&lt;P&gt;First, restructure the code for a certain amount of legibility:&lt;/P&gt;
&lt;PRE&gt;IF Q_4_1_1 NE . THEN DO;
   ChatGPT41 = Q_4_1_1; 
   ChatGPT42 = Q_4_1_2; 
   ChatGPT43 = Q_4_1_3; 
   ChatGPT5 = Q_5_1; 
   ChatGPT6 = Q_6_1; 
   ChatGPT7 = Q_7_1;
END;

IF Q_4_2_1 NE . THEN DO;
   ChatGPT41 = Q_4_2_1; 
   ChatGPT42 = Q_4_2_2; 
   ChatGPT43 = Q_4_2_3; 
   ChatGPT5 = Q_5_2; 
   ChatGPT6 = Q_6_2; 
   ChatGPT7 = Q_7_2;
END;
IF Q_4_3_1 NE . THEN DO;
   ChatGPT41 = Q_4_3_1; 
   ChatGPT42 = Q_4_3_2; 
   ChatGPT43 = Q_4_3_3; 
   ChatGPT5 = Q_5_3; 
   ChatGPT6 = Q_6_3; 
   ChatGPT7 = Q_7_3;
END;
IF Q_4_4_1 NE . THEN DO;
   ChatGPT41 = Q_4_4_1; 
   ChatGPT42 = Q_4_4_2; 
   ChatGPT43 = Q_4_4_3; 
   ChatGPT5 = Q_5_4; 
   ChatGPT6 = Q_6_4; 
   ChatGPT7 = Q_7_4;
END;
ELSE ChatGPT41 = Q_4_5_1; 
ChatGPT42 = Q_4_5_2; 
ChatGPT43 = Q_4_5_3; 
ChatGPT5 = Q_5_5; 
ChatGPT6 = Q_6_5; 
ChatGPT7 = Q_7_5;&lt;/PRE&gt;
&lt;P&gt;This shows that the ELSE only applies to one variable ChatGPT41. The other following variable assignments are not conditional in any way. So any values set previously in the do loops would be unconditionally set.&lt;/P&gt;
&lt;P&gt;I suspect you may have meant for the Else to look more like this:&lt;/P&gt;
&lt;PRE&gt;IF Q_4_1_1 NE . THEN DO;
   ChatGPT41 = Q_4_1_1; 
   ChatGPT42 = Q_4_1_2; 
   ChatGPT43 = Q_4_1_3; 
   ChatGPT5 = Q_5_1; 
   ChatGPT6 = Q_6_1; 
   ChatGPT7 = Q_7_1;
END;

IF Q_4_2_1 NE . THEN DO;
   ChatGPT41 = Q_4_2_1; 
   ChatGPT42 = Q_4_2_2; 
   ChatGPT43 = Q_4_2_3; 
   ChatGPT5 = Q_5_2; 
   ChatGPT6 = Q_6_2; 
   ChatGPT7 = Q_7_2;
END;
IF Q_4_3_1 NE . THEN DO;
   ChatGPT41 = Q_4_3_1; 
   ChatGPT42 = Q_4_3_2; 
   ChatGPT43 = Q_4_3_3; 
   ChatGPT5 = Q_5_3; 
   ChatGPT6 = Q_6_3; 
   ChatGPT7 = Q_7_3;
END;
IF Q_4_4_1 NE . THEN DO;
   ChatGPT41 = Q_4_4_1; 
   ChatGPT42 = Q_4_4_2; 
   ChatGPT43 = Q_4_4_3; 
   ChatGPT5 = Q_5_4; 
   ChatGPT6 = Q_6_4; 
   ChatGPT7 = Q_7_4;
END;
ELSE do;
   ChatGPT41 = Q_4_5_1; 
   ChatGPT42 = Q_4_5_2; 
   ChatGPT43 = Q_4_5_3; 
   ChatGPT5 = Q_5_5; 
   ChatGPT6 = Q_6_5; 
   ChatGPT7 = Q_7_5;
end;&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;HOWEVER that else &lt;/STRONG&gt;ONLY applies when the IF Q_4_4_1 is missing ( So values that should have been assigned in the other IF then do are replaced. For example if all of Q_4_1_1, Q_4_2_1, Q_4_3_1, Q_4_4_1 are not missing which assignment should take priority? You do have &lt;STRONG&gt;4 &lt;/STRONG&gt;Do loops.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You have something like 30+ variables with no provided values or expected results. You should fix that, as in provide values for the variables and the expected results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Personally seeing ChatGPT in those variables makes be cringe that some other terrible almost working code is being modified blindly without a clear knowledge of what the code is supposed to actually do.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Feb 2024 18:31:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-in-a-DO-loop/m-p/916529#M360996</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-02-16T18:31:45Z</dc:date>
    </item>
    <item>
      <title>Re: Error in a DO loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-in-a-DO-loop/m-p/916565#M360997</link>
      <description>&lt;P&gt;That did the trick. Thanks so much for your help!&lt;/P&gt;</description>
      <pubDate>Fri, 16 Feb 2024 19:59:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-in-a-DO-loop/m-p/916565#M360997</guid>
      <dc:creator>newtriks</dc:creator>
      <dc:date>2024-02-16T19:59:14Z</dc:date>
    </item>
    <item>
      <title>Re: Error in a DO loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-in-a-DO-loop/m-p/916566#M360998</link>
      <description>&lt;P&gt;Thanks for your help!&lt;/P&gt;</description>
      <pubDate>Fri, 16 Feb 2024 19:59:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-in-a-DO-loop/m-p/916566#M360998</guid>
      <dc:creator>newtriks</dc:creator>
      <dc:date>2024-02-16T19:59:38Z</dc:date>
    </item>
    <item>
      <title>Re: Error in a DO loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Error-in-a-DO-loop/m-p/916604#M361006</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/413680"&gt;@newtriks&lt;/a&gt;&amp;nbsp;Can you please mark the answer that helped you most as the solution so the rest of us know that your question has been resolved. ...and in the future others with a similar problem searching the communities can find the solution quicker.&lt;/P&gt;</description>
      <pubDate>Sat, 17 Feb 2024 03:20:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Error-in-a-DO-loop/m-p/916604#M361006</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-02-17T03:20:12Z</dc:date>
    </item>
  </channel>
</rss>

