<?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: Array-understand the code that check if customer touch Failure during 6 months in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Array-understand-the-code-that-check-if-customer-touch-Failure/m-p/626804#M184917</link>
    <description>&lt;P&gt;I just don't understand how the code is working.&lt;/P&gt;
&lt;P&gt;Let's look for example at&amp;nbsp; ID 2 that have scores&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token data string"&gt;8 8 11 11 11 10&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;diag{1}&amp;nbsp; is 8 so&amp;nbsp;Flag_Failure=0&lt;/P&gt;
&lt;P&gt;then&amp;nbsp;diag{2}&amp;nbsp; is 8 so&amp;nbsp;Flag_Failure=0&lt;/P&gt;
&lt;P&gt;then&amp;nbsp;diag{3}&amp;nbsp; is 11 so&amp;nbsp;Flag_Failure=1&lt;/P&gt;
&lt;P&gt;then&amp;nbsp;diag{4}&amp;nbsp; is 11 so&amp;nbsp;Flag_Failure=1&lt;/P&gt;
&lt;P&gt;then&amp;nbsp;diag{5}&amp;nbsp; is 11 so&amp;nbsp;Flag_Failure=1&lt;/P&gt;
&lt;P&gt;then&amp;nbsp;diag{6}&amp;nbsp; is 11 so&amp;nbsp;Flag_Failure=0&lt;/P&gt;
&lt;P&gt;So why finally we get&amp;nbsp;Flag_Failure=1???&lt;/P&gt;</description>
    <pubDate>Mon, 24 Feb 2020 06:36:49 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2020-02-24T06:36:49Z</dc:date>
    <item>
      <title>Array-understand the code that check if customer touch Failure during 6 months</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-understand-the-code-that-check-if-customer-touch-Failure/m-p/626800#M184913</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;For each customer ID there is information of score in 6 months.&lt;/P&gt;
&lt;P&gt;I want to check for each customer if he/she touch score 11 (Score 11 meaning is failure).&lt;/P&gt;
&lt;P&gt;This code is working perfect.&lt;/P&gt;
&lt;P&gt;However ,I want to understand how it works.&lt;/P&gt;
&lt;P&gt;As I see the new variable "Flag_Failure" remember the value that was before (IF it was 11 ).&lt;/P&gt;
&lt;P&gt;May anyone explain please?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data a;
input ID Score1 Score2 Score3 Score4 Score5 Score6;
cards;
1 2 2 2 2 2 3
2 8 8 11 11 11 10
3 7 6 7 7 8 8 
4 11 11 11 11 10 10
;
run;

Data b;
set a;
Flag_Failure=0;
array diag{6} Score1-Score6;
do i=1 to 6;
if diag{i} in (11)then Flag_Failure=1;
end;
Drop i;
Run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 24 Feb 2020 05:38:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-understand-the-code-that-check-if-customer-touch-Failure/m-p/626800#M184913</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2020-02-24T05:38:50Z</dc:date>
    </item>
    <item>
      <title>Re: Array-understand the code that check if customer touch Failure during 6 months</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-understand-the-code-that-check-if-customer-touch-Failure/m-p/626803#M184916</link>
      <description>&lt;P&gt;You are correct. The indicator variable i runs through the array and sets&amp;nbsp;&lt;SPAN&gt;Flag_Failure to 1 if it encounters a 11 value. Simple as that. You may consider using the Whichn Function for a job like this though..&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data b;
   set a;
   Flag_Failure = whichn(11, of score:) &amp;gt; 0;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 24 Feb 2020 06:11:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-understand-the-code-that-check-if-customer-touch-Failure/m-p/626803#M184916</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-02-24T06:11:30Z</dc:date>
    </item>
    <item>
      <title>Re: Array-understand the code that check if customer touch Failure during 6 months</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-understand-the-code-that-check-if-customer-touch-Failure/m-p/626804#M184917</link>
      <description>&lt;P&gt;I just don't understand how the code is working.&lt;/P&gt;
&lt;P&gt;Let's look for example at&amp;nbsp; ID 2 that have scores&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token data string"&gt;8 8 11 11 11 10&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;diag{1}&amp;nbsp; is 8 so&amp;nbsp;Flag_Failure=0&lt;/P&gt;
&lt;P&gt;then&amp;nbsp;diag{2}&amp;nbsp; is 8 so&amp;nbsp;Flag_Failure=0&lt;/P&gt;
&lt;P&gt;then&amp;nbsp;diag{3}&amp;nbsp; is 11 so&amp;nbsp;Flag_Failure=1&lt;/P&gt;
&lt;P&gt;then&amp;nbsp;diag{4}&amp;nbsp; is 11 so&amp;nbsp;Flag_Failure=1&lt;/P&gt;
&lt;P&gt;then&amp;nbsp;diag{5}&amp;nbsp; is 11 so&amp;nbsp;Flag_Failure=1&lt;/P&gt;
&lt;P&gt;then&amp;nbsp;diag{6}&amp;nbsp; is 11 so&amp;nbsp;Flag_Failure=0&lt;/P&gt;
&lt;P&gt;So why finally we get&amp;nbsp;Flag_Failure=1???&lt;/P&gt;</description>
      <pubDate>Mon, 24 Feb 2020 06:36:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-understand-the-code-that-check-if-customer-touch-Failure/m-p/626804#M184917</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2020-02-24T06:36:49Z</dc:date>
    </item>
    <item>
      <title>Re: Array-understand the code that check if customer touch Failure during 6 months</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-understand-the-code-that-check-if-customer-touch-Failure/m-p/626806#M184919</link>
      <description>&lt;P&gt;Think of it this way: If the i'th element of the array is 11 then Flag_Failure=1. Else do not touch&amp;nbsp;Flag_Failure. That means that&amp;nbsp;Flag_Failure will be 1 if just one of the elements is equal to 11. SAS does not reinitialize the variable within the loop. You do that yourself before the loop with Flag_Failure=0. I added a few Put Statements to your code below, hopefully it will make more sense.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data b;
    set a;
    Flag_Failure=0;
    array diag{6} Score1-Score6;

    put "Before Loop: " Flag_Failure=;

    do i=1 to 6;
        if diag{i} in (11) then Flag_Failure=1;
        
        put "Inside Loop: " (diag[i])(=)Flag_Failure=;

    end;

    put "After Loop: " Flag_Failure= //;

    Drop i;
Run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 24 Feb 2020 07:08:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-understand-the-code-that-check-if-customer-touch-Failure/m-p/626806#M184919</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-02-24T07:08:25Z</dc:date>
    </item>
  </channel>
</rss>

