<?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: Need help with array to check multiple iterations of one variable to create a new one in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-array-to-check-multiple-iterations-of-one/m-p/976250#M378290</link>
    <description>&lt;P&gt;Alternatively, you could store the exact value of &lt;FONT face="courier new,courier"&gt;max(of result1-result16)&lt;/FONT&gt; in variable &lt;FONT face="courier new,courier"&gt;SummaryResult&lt;/FONT&gt; (and thus have more information available) and define a format to display 100 as "UNKNOWN", 200 as "NO", etc.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
value sumres
  .='MISSING'
100='UNKNOWN'
200='NO'
300-high='YES'
other='STRANGE' 
;
run;

data want;
set have;
if n(of result:) then SummaryResult=max(of result:);
format SummaryResult sumres.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This formatted variable could be used in CLASS statements (e.g. in PROC MEANS), as a group variable in PROC REPORT,&amp;nbsp;for creating frequency tables (with PROC FREQ), etc. However, it would be slightly less convenient than a character variable if you had to retrieve the formatted values very often (as in&amp;nbsp;&lt;FONT face="courier new,courier"&gt;if &lt;STRONG&gt;vvalue(&lt;/STRONG&gt;SummaryResult&lt;STRONG&gt;)&lt;/STRONG&gt;='YES' then&lt;/FONT&gt; ...).&lt;/P&gt;</description>
    <pubDate>Thu, 02 Oct 2025 16:02:59 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2025-10-02T16:02:59Z</dc:date>
    <item>
      <title>Need help with array to check multiple iterations of one variable to create a new one</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-array-to-check-multiple-iterations-of-one/m-p/976243#M378286</link>
      <description>&lt;P&gt;I have a messy dataset where I have up to 16 iterations of a variable Result1-Result16. Some people in the dataset only have a few iterations, some have 16 and everywhere in between. I'm trying to create a result summary variable that takes into account each of these versions. The Result variable is in number form and I have a format for it that interprets what the numbers mean, I'm not sure if that matters for the coding. When interpreting the result options into the SummaryResult variable I'd like to create, some only match up with one interpretation but others should be grouped together since they mean essentially the same thing for the SummaryResult variable. For example:&lt;/P&gt;
&lt;P&gt;A result of 100 means UNKNOWN&lt;/P&gt;
&lt;P&gt;A result of 200 means NO&lt;/P&gt;
&lt;P&gt;But then a result of 300, 400, 500, etc means YES&lt;/P&gt;
&lt;P&gt;Many are also missing with . as the result, so the ResultSummary should be . also&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To complicate matters, I can't just look at the last/highest iteration of Result because the correct/best ResultSummary may not be there, it could be the first or middle or last. The ResultSummary should be determined by a hierarchy:&lt;/P&gt;
&lt;P&gt;If there are any results that mean YES, the ResultSummary variable should be YES.&lt;/P&gt;
&lt;P&gt;If there are no YES results, but there is at least one NO, the ResultSummary variable should be NO.&lt;/P&gt;
&lt;P&gt;If there are no YES or NO results, but there is at least one UNKNOWN, the ResultSummary variable should be UNKNOWN.&lt;/P&gt;
&lt;P&gt;If . is the only result for all iterations of Result for that person, the ResultSummary should be . (missing).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is a fake example:&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 336pt;" border="0" width="448" cellspacing="0" cellpadding="0"&gt;&lt;COLGROUP&gt;&lt;COL style="width: 48pt;" span="7" width="64" /&gt; &lt;/COLGROUP&gt;
&lt;TBODY&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD width="64" height="19" class="xl63" style="height: 14.5pt; width: 48pt;"&gt;Person&lt;/TD&gt;
&lt;TD width="64" class="xl63" style="border-left: none; width: 48pt;"&gt;Result1&lt;/TD&gt;
&lt;TD width="64" class="xl63" style="border-left: none; width: 48pt;"&gt;Result2&lt;/TD&gt;
&lt;TD width="64" class="xl63" style="border-left: none; width: 48pt;"&gt;Result3&lt;/TD&gt;
&lt;TD width="64" class="xl63" style="border-left: none; width: 48pt;"&gt;Result4&lt;/TD&gt;
&lt;TD width="64" class="xl63" style="border-left: none; width: 48pt;"&gt;Result5&lt;/TD&gt;
&lt;TD width="64" class="xl63" style="border-left: none; width: 48pt;"&gt;SummaryResult&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD height="19" align="right" class="xl63" style="height: 14.5pt; border-top: none;"&gt;111&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;.&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;.&lt;/TD&gt;
&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;100&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;.&lt;/TD&gt;
&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;100&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;UNKNOWN&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD height="19" align="right" class="xl63" style="height: 14.5pt; border-top: none;"&gt;112&lt;/TD&gt;
&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;200&lt;/TD&gt;
&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;200&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;.&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;.&lt;/TD&gt;
&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;500&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;YES&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD height="19" align="right" class="xl63" style="height: 14.5pt; border-top: none;"&gt;113&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;.&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;.&lt;/TD&gt;
&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;100&lt;/TD&gt;
&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;200&lt;/TD&gt;
&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;200&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;NO&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD height="19" align="right" class="xl63" style="height: 14.5pt; border-top: none;"&gt;114&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;.&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;.&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;.&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;.&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;.&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;.&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 14.5pt;"&gt;
&lt;TD height="19" align="right" class="xl63" style="height: 14.5pt; border-top: none;"&gt;115&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;.&lt;/TD&gt;
&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;300&lt;/TD&gt;
&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;100&lt;/TD&gt;
&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;100&lt;/TD&gt;
&lt;TD align="right" class="xl63" style="border-top: none; border-left: none;"&gt;400&lt;/TD&gt;
&lt;TD class="xl63" style="border-top: none; border-left: none;"&gt;YES&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I know only basics about assays from a class about 6 years ago and I just can't wrap my head around how I could get it to check each iteration while not keeping the last version instead of the best summary based on the hierarchy.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for any help!!&lt;/P&gt;</description>
      <pubDate>Thu, 02 Oct 2025 14:45:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-with-array-to-check-multiple-iterations-of-one/m-p/976243#M378286</guid>
      <dc:creator>Geoghegan</dc:creator>
      <dc:date>2025-10-02T14:45:24Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with array to check multiple iterations of one variable to create a new one</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-array-to-check-multiple-iterations-of-one/m-p/976245#M378287</link>
      <description>&lt;P&gt;Something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;length summaryresult $7;
array res [*] result1-result5;
select (max(of res[*]));
  when (300,400,500) summaryresult = "YES";
  when (200) summaryresult = "NO";
  when (100) summaryresult = "UNKNOWN";
  otherwise summaryresult = ".";
end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Oct 2025 15:01:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-with-array-to-check-multiple-iterations-of-one/m-p/976245#M378287</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2025-10-02T15:01:29Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with array to check multiple iterations of one variable to create a new one</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-array-to-check-multiple-iterations-of-one/m-p/976250#M378290</link>
      <description>&lt;P&gt;Alternatively, you could store the exact value of &lt;FONT face="courier new,courier"&gt;max(of result1-result16)&lt;/FONT&gt; in variable &lt;FONT face="courier new,courier"&gt;SummaryResult&lt;/FONT&gt; (and thus have more information available) and define a format to display 100 as "UNKNOWN", 200 as "NO", etc.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
value sumres
  .='MISSING'
100='UNKNOWN'
200='NO'
300-high='YES'
other='STRANGE' 
;
run;

data want;
set have;
if n(of result:) then SummaryResult=max(of result:);
format SummaryResult sumres.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This formatted variable could be used in CLASS statements (e.g. in PROC MEANS), as a group variable in PROC REPORT,&amp;nbsp;for creating frequency tables (with PROC FREQ), etc. However, it would be slightly less convenient than a character variable if you had to retrieve the formatted values very often (as in&amp;nbsp;&lt;FONT face="courier new,courier"&gt;if &lt;STRONG&gt;vvalue(&lt;/STRONG&gt;SummaryResult&lt;STRONG&gt;)&lt;/STRONG&gt;='YES' then&lt;/FONT&gt; ...).&lt;/P&gt;</description>
      <pubDate>Thu, 02 Oct 2025 16:02:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-with-array-to-check-multiple-iterations-of-one/m-p/976250#M378290</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2025-10-02T16:02:59Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with array to check multiple iterations of one variable to create a new one</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-array-to-check-multiple-iterations-of-one/m-p/976301#M378293</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards truncover expandtabs;
input Person	Result1	Result2	Result3	Result4	Result5	;
cards;
111	.	.	100	.	100	
112	200	200	.	.	500	
113	.	.	100	200	200	
114	.	.	.	.	.	
115	.	300	100	100	400	
;


data want;
 set have;
 array x{*} Result:;
 length ResultSummary $ 40;
 if (300 in x) or (400 in x) or (500 in x)  then ResultSummary ='YES ';
  else  if 200 in x then ResultSummary ='NO ';
    else if 100 in x then ResultSummary ='UNKNOWN';
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 03 Oct 2025 03:45:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-with-array-to-check-multiple-iterations-of-one/m-p/976301#M378293</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-10-03T03:45:21Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with array to check multiple iterations of one variable to create a new one</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-array-to-check-multiple-iterations-of-one/m-p/976407#M378309</link>
      <description>&lt;P&gt;Thank you! My example used fake numbers but I adjusted a few of mine to be in a descending order like my example and your suggestion worked, thank you!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks others for the ideas, if I have to do further I'll keep them in mind!&lt;/P&gt;</description>
      <pubDate>Sat, 04 Oct 2025 19:58:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-with-array-to-check-multiple-iterations-of-one/m-p/976407#M378309</guid>
      <dc:creator>Geoghegan</dc:creator>
      <dc:date>2025-10-04T19:58:54Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with array to check multiple iterations of one variable to create a new one</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-with-array-to-check-multiple-iterations-of-one/m-p/976410#M378312</link>
      <description>&lt;P&gt;Note that the ARRAY is not needed for this solution since you only need the list of variables once you can just place the list into the function call directly.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select (max(of result1-result5));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 04 Oct 2025 22:00:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-with-array-to-check-multiple-iterations-of-one/m-p/976410#M378312</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-10-04T22:00:25Z</dc:date>
    </item>
  </channel>
</rss>

