<?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 Evaluate all array elements using 'do loop' to create a single variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Evaluate-all-array-elements-using-do-loop-to-create-a-single/m-p/545061#M150752</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to use an array and 'do loop' to create a new summary variable based on the evaluation of all the array variables, but the result I get is based on only the last variable in the array. Basically, I'm trying to evaluate 6 variables to determine the value of 1 new variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have 6 genetic test status result variables: 'OverallTestStatus_Result_1' through&amp;nbsp;'OverallTestStatus_Result_6', and they are coded&amp;nbsp;-1="True Negative;&amp;nbsp;0="Variant"; and&amp;nbsp;1="True Positive". My data has 1 record per Subject.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If a Subject has a "True Positive" (code 1) for ANY of their 6 result variables, then they should get a value of 1 (Positive) for the new summary variable 'genetic_test_summary'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If a Subject doesn't have a "True Positive" (code 1) for ANY of their 6 result variables, but they do have a "Variant' (coded 0) for ANY of their 6 result variables, then they should get a value of 0 (Variant) for the new variable 'genetic_test_summary'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And finally, if&amp;nbsp;a Subject has a "True Negative" (code -1) for ALL of their 6 result variables, then they should get a value of -1 (Negative) for the new summary variable 'genetic_test_summary'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I thought that using 'else if' would work to address the ANY vs. ALL requirement/condition for the different summary variable value scenarios, but it does not.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can this be done with a 'do loop'? How do I evaluate every element of the array, not just the last, and is there a way to evaluate different array elements with 'AND' or 'OR'?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A snip of my code is below, but it doesn't work. If a subject has a "True Positive" (code 1) for their first 5 result variables, and the 6th result variable is a "Variant" (code 0), then the summary variable 'genetic_test_summary'&amp;nbsp;gets coded 0 (Variant).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Creating a summary variable (for anyone tested)       */
/* to denote  "Positive" (any overallteststatus that     */
/* includes a "True positive"); and if all true negative */
/* then it would be coded be as "Negative"; if there is  */
/* a variant, would be "variant" (except if there was    */
/* also a positive test result, then this would trump    */
/* "variant").                                           */

array OverallTestStatusArr {6} OverallTestStatus_Result_1 OverallTestStatus_Result_2 OverallTestStatus_Result_3
                               OverallTestStatus_Result_4 OverallTestStatus_Result_5 OverallTestStatus_Result_6;

do i = 1 to 6 while(OverallTestStatusArr{i} ne .);
       if OverallTestStatusArr{i}=1 then genetic_test_summary=1; /* Positive */
  else if OverallTestStatusArr{i}=0  then genetic_test_summary=0; /* Variant */
  else if OverallTestStatusArr{i}=-1 then genetic_test_summary=-1; /* Negative */
end;
drop i;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
    <pubDate>Thu, 21 Mar 2019 21:27:24 GMT</pubDate>
    <dc:creator>gkirkner</dc:creator>
    <dc:date>2019-03-21T21:27:24Z</dc:date>
    <item>
      <title>Evaluate all array elements using 'do loop' to create a single variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Evaluate-all-array-elements-using-do-loop-to-create-a-single/m-p/545061#M150752</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to use an array and 'do loop' to create a new summary variable based on the evaluation of all the array variables, but the result I get is based on only the last variable in the array. Basically, I'm trying to evaluate 6 variables to determine the value of 1 new variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have 6 genetic test status result variables: 'OverallTestStatus_Result_1' through&amp;nbsp;'OverallTestStatus_Result_6', and they are coded&amp;nbsp;-1="True Negative;&amp;nbsp;0="Variant"; and&amp;nbsp;1="True Positive". My data has 1 record per Subject.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If a Subject has a "True Positive" (code 1) for ANY of their 6 result variables, then they should get a value of 1 (Positive) for the new summary variable 'genetic_test_summary'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If a Subject doesn't have a "True Positive" (code 1) for ANY of their 6 result variables, but they do have a "Variant' (coded 0) for ANY of their 6 result variables, then they should get a value of 0 (Variant) for the new variable 'genetic_test_summary'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And finally, if&amp;nbsp;a Subject has a "True Negative" (code -1) for ALL of their 6 result variables, then they should get a value of -1 (Negative) for the new summary variable 'genetic_test_summary'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I thought that using 'else if' would work to address the ANY vs. ALL requirement/condition for the different summary variable value scenarios, but it does not.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can this be done with a 'do loop'? How do I evaluate every element of the array, not just the last, and is there a way to evaluate different array elements with 'AND' or 'OR'?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A snip of my code is below, but it doesn't work. If a subject has a "True Positive" (code 1) for their first 5 result variables, and the 6th result variable is a "Variant" (code 0), then the summary variable 'genetic_test_summary'&amp;nbsp;gets coded 0 (Variant).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Creating a summary variable (for anyone tested)       */
/* to denote  "Positive" (any overallteststatus that     */
/* includes a "True positive"); and if all true negative */
/* then it would be coded be as "Negative"; if there is  */
/* a variant, would be "variant" (except if there was    */
/* also a positive test result, then this would trump    */
/* "variant").                                           */

array OverallTestStatusArr {6} OverallTestStatus_Result_1 OverallTestStatus_Result_2 OverallTestStatus_Result_3
                               OverallTestStatus_Result_4 OverallTestStatus_Result_5 OverallTestStatus_Result_6;

do i = 1 to 6 while(OverallTestStatusArr{i} ne .);
       if OverallTestStatusArr{i}=1 then genetic_test_summary=1; /* Positive */
  else if OverallTestStatusArr{i}=0  then genetic_test_summary=0; /* Variant */
  else if OverallTestStatusArr{i}=-1 then genetic_test_summary=-1; /* Negative */
end;
drop i;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Mar 2019 21:27:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Evaluate-all-array-elements-using-do-loop-to-create-a-single/m-p/545061#M150752</guid>
      <dc:creator>gkirkner</dc:creator>
      <dc:date>2019-03-21T21:27:24Z</dc:date>
    </item>
    <item>
      <title>Re: Evaluate all array elements using 'do loop' to create a single variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Evaluate-all-array-elements-using-do-loop-to-create-a-single/m-p/545097#M150762</link>
      <description>&lt;P&gt;You have to decide what to do if there might be missing values in the data.&amp;nbsp; Other than that, a single statement should compute the result you are asking for:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;genetic_test_summary = max(of Overall_Test_Status_Result_: );&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This assumes that the six variables you mention are the only ones with names that begin with "Overall_Test_Status_Result_").&lt;/P&gt;</description>
      <pubDate>Fri, 22 Mar 2019 01:02:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Evaluate-all-array-elements-using-do-loop-to-create-a-single/m-p/545097#M150762</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-03-22T01:02:17Z</dc:date>
    </item>
    <item>
      <title>Re: Evaluate all array elements using 'do loop' to create a single variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Evaluate-all-array-elements-using-do-loop-to-create-a-single/m-p/545226#M150801</link>
      <description>&lt;P&gt;Thanks, Astounding! This worked, and I was apparently way overthinking this.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Mar 2019 13:58:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Evaluate-all-array-elements-using-do-loop-to-create-a-single/m-p/545226#M150801</guid>
      <dc:creator>gkirkner</dc:creator>
      <dc:date>2019-03-22T13:58:26Z</dc:date>
    </item>
  </channel>
</rss>

