<?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: Flag and count matches across 2 sets of arrays (4 variables each set) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Flag-and-count-matches-across-2-sets-of-arrays-4-variables-each/m-p/889020#M351207</link>
    <description>&lt;P&gt;Assuming&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;There are no duplicates in KOL1-KOL4 (but there could be in MT1-MT4), and&lt;/LI&gt;
&lt;LI&gt;Missing values present in both arrays are not eligible to be counted as matches&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;then:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop=m);
  set have;
  array ko{*} kol1-kol4;
  array mt{*} mt1-mt4;
  do m=1 to dim(mt);
    count=sum(count,whichn(mt{m},of ko{*})&amp;gt;0);
  end;
  flag=(count&amp;gt;0);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 12 Aug 2023 03:05:06 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2023-08-12T03:05:06Z</dc:date>
    <item>
      <title>Flag and count matches across 2 sets of arrays (4 variables each set)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flag-and-count-matches-across-2-sets-of-arrays-4-variables-each/m-p/888974#M351189</link>
      <description>&lt;P&gt;Hi Gents,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to flag and count matches across 2 &lt;STRONG&gt;sets&lt;/STRONG&gt; of variables (KOL1-KOL4 compared to MT1-MT4). I think this is considered an many-to-many array match, but I am not advanced to know what to look for?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;WANT: if ANY value in KOL1 or KOL2 or KOL3 or KOL4 is found in ANY value from variables MT1 or MT2 or MT3 or MT4&lt;/P&gt;&lt;P&gt;then create &lt;STRONG&gt;new variable FLAG=1&lt;/STRONG&gt; and &lt;STRONG&gt;count the number of matches&lt;/STRONG&gt; as COUNT=n.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So for example,&amp;nbsp;&lt;/P&gt;&lt;P&gt;if KOL1=MT2 then Flag=1 and Count=1;&lt;/P&gt;&lt;P&gt;if KOL1=MT3 and KOL2=MT1 then Flag=1 and Count=2;&lt;/P&gt;&lt;P&gt;et cetera.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried coding the combinations in an if...else if... logic but there's 41 possible values for each of the variables and there's 8 variables...so 328 combinations is just too much to hard code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is much appreciated. Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Aug 2023 17:57:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flag-and-count-matches-across-2-sets-of-arrays-4-variables-each/m-p/888974#M351189</guid>
      <dc:creator>AlexPaezSilva</dc:creator>
      <dc:date>2023-08-11T17:57:05Z</dc:date>
    </item>
    <item>
      <title>Re: Flag and count matches across 2 sets of arrays (4 variables each set)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flag-and-count-matches-across-2-sets-of-arrays-4-variables-each/m-p/888976#M351190</link>
      <description>&lt;P&gt;No example data so this is a guess for a place to start.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want;
   set have;
   array k(*) kol1-kol4;
   array m(*) mt1-mt4;
   do i=1 to dim(k);
      do j=1 to dim(m);
         if k[i]=m[j] then do;
            flag=1;
            count=sum(count,1);
         end;
      end;
   end;
   drop i j;
run;
&lt;/PRE&gt;
&lt;P&gt;Unless you are trying to do a count per specific value then the actual value of the variables in question isn't really pertinent to the flag and match count.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the above doesn't provide a moderately good start then 1) provide example data in the form of data step code and 2) what you expect for the given data&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/403694"&gt;@AlexPaezSilva&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi Gents,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to flag and count matches across 2 &lt;STRONG&gt;sets&lt;/STRONG&gt; of variables (KOL1-KOL4 compared to MT1-MT4). I think this is considered an many-to-many array match, but I am not advanced to know what to look for?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;WANT: if ANY value in KOL1 or KOL2 or KOL3 or KOL4 is found in ANY value from variables MT1 or MT2 or MT3 or MT4&lt;/P&gt;
&lt;P&gt;then create &lt;STRONG&gt;new variable FLAG=1&lt;/STRONG&gt; and &lt;STRONG&gt;count the number of matches&lt;/STRONG&gt; as COUNT=n.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So for example,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if KOL1=MT2 then Flag=1 and Count=1;&lt;/P&gt;
&lt;P&gt;if KOL1=MT3 and KOL2=MT1 then Flag=1 and Count=2;&lt;/P&gt;
&lt;P&gt;et cetera.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried coding the combinations in an if...else if... logic but there's 41 possible values for each of the variables and there's 8 variables...so 328 combinations is just too much to hard code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help is much appreciated. Thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Aug 2023 18:05:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flag-and-count-matches-across-2-sets-of-arrays-4-variables-each/m-p/888976#M351190</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-08-11T18:05:12Z</dc:date>
    </item>
    <item>
      <title>Re: Flag and count matches across 2 sets of arrays (4 variables each set)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flag-and-count-matches-across-2-sets-of-arrays-4-variables-each/m-p/888999#M351193</link>
      <description>&lt;P&gt;Within the array KOL1-KOl4, are there duplicates?&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;And within the array MT1-MT4, are there duplicates?&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This would influence the construction of the loops over the array elements.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How about some sample data, in the form of a working DATA step?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Oh yes,&amp;nbsp; And do the KOL or MT variables ever have a missing value?&amp;nbsp; And if so, can missing values in both arrays constitute a match?&lt;/P&gt;</description>
      <pubDate>Fri, 11 Aug 2023 22:15:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flag-and-count-matches-across-2-sets-of-arrays-4-variables-each/m-p/888999#M351193</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2023-08-11T22:15:32Z</dc:date>
    </item>
    <item>
      <title>Re: Flag and count matches across 2 sets of arrays (4 variables each set)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flag-and-count-matches-across-2-sets-of-arrays-4-variables-each/m-p/889020#M351207</link>
      <description>&lt;P&gt;Assuming&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;There are no duplicates in KOL1-KOL4 (but there could be in MT1-MT4), and&lt;/LI&gt;
&lt;LI&gt;Missing values present in both arrays are not eligible to be counted as matches&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;then:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop=m);
  set have;
  array ko{*} kol1-kol4;
  array mt{*} mt1-mt4;
  do m=1 to dim(mt);
    count=sum(count,whichn(mt{m},of ko{*})&amp;gt;0);
  end;
  flag=(count&amp;gt;0);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 12 Aug 2023 03:05:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flag-and-count-matches-across-2-sets-of-arrays-4-variables-each/m-p/889020#M351207</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2023-08-12T03:05:06Z</dc:date>
    </item>
    <item>
      <title>Re: Flag and count matches across 2 sets of arrays (4 variables each set)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flag-and-count-matches-across-2-sets-of-arrays-4-variables-each/m-p/893843#M353101</link>
      <description>I came across this thread after having a similar problem. The code you provided works but it seems to be counting the missing as a match. Am I overlooking something?</description>
      <pubDate>Tue, 12 Sep 2023 16:32:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flag-and-count-matches-across-2-sets-of-arrays-4-variables-each/m-p/893843#M353101</guid>
      <dc:creator>erfr225</dc:creator>
      <dc:date>2023-09-12T16:32:15Z</dc:date>
    </item>
  </channel>
</rss>

