<?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 The ELSE statement in my Array overwriting original If statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/The-ELSE-statement-in-my-Array-overwriting-original-If-statement/m-p/973450#M377686</link>
    <description>&lt;P&gt;I am having an issue when using if-then-else in an array.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the code I want to use, but when it runs it seems to ignore the original if statement as you can see in the image there are individuals who have "Achieved" selected and the AchievedGoal variable is listed as "No".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;data DSMESY2_test;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;set DSMESY2;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;array Ace ProblemSolving ReducingRisk BeingActive HealthyCoping HealthyEating Monitoring TakingMeds;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;do over Ace;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;if Ace = "Achieved" then AchievedGoal="Yes";&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;else AchievedGoal="No";&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;end;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;run;&lt;/DIV&gt;&lt;DIV&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SAS Image 1.png" style="width: 669px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/109345iE8213C051DB164D2/image-size/large?v=v2&amp;amp;px=999" role="button" title="SAS Image 1.png" alt="SAS Image 1.png" /&gt;&lt;/span&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;When I removed the "Else &lt;SPAN&gt;AchievedGoal="No"; statement, the array seems to work properly though.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;data DSMESY2_test;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;set DSMESY2;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;array Ace ProblemSolving ReducingRisk BeingActive HealthyCoping HealthyEating Monitoring TakingMeds;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;do over Ace;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;if Ace = "Achieved" then AchievedGoal="Yes";&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;end;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;run;&lt;/DIV&gt;&lt;DIV&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SAS Image 2.png" style="width: 686px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/109346iA4F36A621D54C81B/image-size/large?v=v2&amp;amp;px=999" role="button" title="SAS Image 2.png" alt="SAS Image 2.png" /&gt;&lt;/span&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;I have tried to trouble shoot this so many times and I can't figure out what is going on. I can do a work around for my reporting by doing a proc freq/missing, for the second code, but it is driving me crazy not knowing why the top code isn't working especially because I know I have used it with other datasets with now issue.&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
    <pubDate>Wed, 27 Aug 2025 20:04:56 GMT</pubDate>
    <dc:creator>aberkowitz</dc:creator>
    <dc:date>2025-08-27T20:04:56Z</dc:date>
    <item>
      <title>The ELSE statement in my Array overwriting original If statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-ELSE-statement-in-my-Array-overwriting-original-If-statement/m-p/973450#M377686</link>
      <description>&lt;P&gt;I am having an issue when using if-then-else in an array.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the code I want to use, but when it runs it seems to ignore the original if statement as you can see in the image there are individuals who have "Achieved" selected and the AchievedGoal variable is listed as "No".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;data DSMESY2_test;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;set DSMESY2;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;array Ace ProblemSolving ReducingRisk BeingActive HealthyCoping HealthyEating Monitoring TakingMeds;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;do over Ace;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;if Ace = "Achieved" then AchievedGoal="Yes";&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;else AchievedGoal="No";&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;end;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;run;&lt;/DIV&gt;&lt;DIV&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SAS Image 1.png" style="width: 669px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/109345iE8213C051DB164D2/image-size/large?v=v2&amp;amp;px=999" role="button" title="SAS Image 1.png" alt="SAS Image 1.png" /&gt;&lt;/span&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;When I removed the "Else &lt;SPAN&gt;AchievedGoal="No"; statement, the array seems to work properly though.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;data DSMESY2_test;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;set DSMESY2;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;array Ace ProblemSolving ReducingRisk BeingActive HealthyCoping HealthyEating Monitoring TakingMeds;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;do over Ace;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;if Ace = "Achieved" then AchievedGoal="Yes";&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;end;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;run;&lt;/DIV&gt;&lt;DIV&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SAS Image 2.png" style="width: 686px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/109346iA4F36A621D54C81B/image-size/large?v=v2&amp;amp;px=999" role="button" title="SAS Image 2.png" alt="SAS Image 2.png" /&gt;&lt;/span&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;I have tried to trouble shoot this so many times and I can't figure out what is going on. I can do a work around for my reporting by doing a proc freq/missing, for the second code, but it is driving me crazy not knowing why the top code isn't working especially because I know I have used it with other datasets with now issue.&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 27 Aug 2025 20:04:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-ELSE-statement-in-my-Array-overwriting-original-If-statement/m-p/973450#M377686</guid>
      <dc:creator>aberkowitz</dc:creator>
      <dc:date>2025-08-27T20:04:56Z</dc:date>
    </item>
    <item>
      <title>Re: The ELSE statement in my Array overwriting original If statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-ELSE-statement-in-my-Array-overwriting-original-If-statement/m-p/973452#M377687</link>
      <description>&lt;P&gt;The way you write your code, only the evaluation of the&amp;nbsp;&lt;EM&gt;last&lt;/EM&gt; array element will make it through.&lt;/P&gt;
&lt;P&gt;Restructure your code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;AchievedGoal = "No";
do over Ace;
  if Ace = "Achieved" then AchievedGoal = "Yes";
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Aug 2025 20:16:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-ELSE-statement-in-my-Array-overwriting-original-If-statement/m-p/973452#M377687</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2025-08-27T20:16:02Z</dc:date>
    </item>
    <item>
      <title>Re: The ELSE statement in my Array overwriting original If statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-ELSE-statement-in-my-Array-overwriting-original-If-statement/m-p/973453#M377688</link>
      <description>&lt;P&gt;You were almost there.&lt;/P&gt;
&lt;P&gt;The pattern you want is something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;AchievedGoal="No ";
do over Ace;
  if Ace = "Achieved" then AchievedGoal="Yes";
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You set the result to false before the loop.&amp;nbsp; Then in the loop set it to true when the condition is met.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Aug 2025 20:17:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-ELSE-statement-in-my-Array-overwriting-original-If-statement/m-p/973453#M377688</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-08-27T20:17:46Z</dc:date>
    </item>
    <item>
      <title>Re: The ELSE statement in my Array overwriting original If statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-ELSE-statement-in-my-Array-overwriting-original-If-statement/m-p/973454#M377689</link>
      <description>Thank you! That makes so much sense.</description>
      <pubDate>Wed, 27 Aug 2025 20:26:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-ELSE-statement-in-my-Array-overwriting-original-If-statement/m-p/973454#M377689</guid>
      <dc:creator>aberkowitz</dc:creator>
      <dc:date>2025-08-27T20:26:12Z</dc:date>
    </item>
    <item>
      <title>Re: The ELSE statement in my Array overwriting original If statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-ELSE-statement-in-my-Array-overwriting-original-If-statement/m-p/973457#M377690</link>
      <description>&lt;P&gt;Another option would be to avoid the DO loop and just use the IN operator:&lt;/P&gt;
&lt;PRE&gt;&lt;FONT color="#999999"&gt;data DSMESY2_test;
set DSMESY2;
array Ace ProblemSolving ReducingRisk BeingActive HealthyCoping HealthyEating Monitoring TakingMeds;
&lt;FONT color="#000000"&gt;if &lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;"Achieved" in Ace&lt;/STRONG&gt;&lt;/FONT&gt; then AchievedGoal="Yes";
else AchievedGoal="No";&lt;/FONT&gt;
run;&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;Personally, I would prefer a numeric 0-1 coded variable &lt;FONT face="courier new,courier"&gt;AchievedGoal&lt;/FONT&gt;, which would also avoid the IF-THEN/ELSE statement:&lt;/P&gt;
&lt;PRE&gt;AchievedGoal="Achieved" in Ace;&lt;/PRE&gt;
&lt;P&gt;A format with labels "Yes", "No" could be attached if needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Aug 2025 20:54:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-ELSE-statement-in-my-Array-overwriting-original-If-statement/m-p/973457#M377690</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2025-08-27T20:54:48Z</dc:date>
    </item>
    <item>
      <title>Re: The ELSE statement in my Array overwriting original If statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/The-ELSE-statement-in-my-Array-overwriting-original-If-statement/m-p/973517#M377705</link>
      <description>&lt;P&gt;Another way to deal with this is to use an iterative DO loop (instead of using the DO OVER syntax that SAS has been trying to eliminate).&amp;nbsp; Then you can take advantage of the fact you can combine the iterative DO with an UNTIL() clause.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data DSMESY2_test;
  set DSMESY2;
  array Ace ProblemSolving ReducingRisk BeingActive HealthyCoping 
            HealthyEating Monitoring TakingMeds
  ;
  do index=1 to dim(Ace) until (AchievedGoal);
    AchievedGoal = (Ace[index]="Achieved");
  end;
  drop index;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Aug 2025 14:47:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/The-ELSE-statement-in-my-Array-overwriting-original-If-statement/m-p/973517#M377705</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-08-28T14:47:45Z</dc:date>
    </item>
  </channel>
</rss>

