<?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: mark a specific combination of two variables next to each other in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/mark-a-specific-combination-of-two-variables-next-to-each-other/m-p/806958#M318036</link>
    <description>&lt;P&gt;This too is untested, in the absence of sample data in the form of a working data step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop=i _:);
  array search_strings {9} $8 _temporary_;
  length _part1 $3 _part2 $2  _code_string $200;

  if _n_=1 then do _part1="T1b","T4a","T3a";
    do _part2="M1","M2","U3";
      i+1;
      search_strings{i}=catx('!',_part1,_part2);
      put i=  search_strings{i}=;
    end;
  end;

  set have;
  _code_string=catx('!',of code_:);
  met=0;
  do i=1 to dim(search_strings) until (met=1);
    if findw(_code_string,trim(search_strings{i}),'!')&amp;gt;0 then met=1;
  end;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This works by forming an array of compound terms to search for - each compound term (for example "T1b!M1") formed by concatenating one of the _PART1 expressions followed by a "!" followed by one of the _PART2 expressions - nine compound expressions in your case.&amp;nbsp; The array is declared as _TEMPORARY_ meaning it will not be output, but will be retained throughout the data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then do a similar concatenation of the 44 CODE_ values, also with '!' as a separator.&amp;nbsp; Search that concatenated string for each of the 9 compound search terms until there is success, or you've exhausted the search terms.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Make sure you declare sufficient LENGTHs for the array elements and the other needed variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 09 Apr 2022 22:44:57 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2022-04-09T22:44:57Z</dc:date>
    <item>
      <title>mark a specific combination of two variables next to each other</title>
      <link>https://communities.sas.com/t5/SAS-Programming/mark-a-specific-combination-of-two-variables-next-to-each-other/m-p/806923#M318018</link>
      <description>&lt;P&gt;Can someone help me with a SAS code where a variable,&amp;nbsp;&lt;SPAN class=""&gt;MET, indicates if one of the variables CODE_1-CODE_44 contains one of several codes (T1b, T4a, T3a) and that the subsequent variable (of CODE_1-CODE_44) contains one of several codes (M1, M2, U3).&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;CODE_1&amp;nbsp; CODE_2 CODE_3 CODE_4 .....&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; MET&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;T1b&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;M1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; C2a&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;P4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;T4a&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;M4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; C2a&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;T4a&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;T4a&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;M4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; T1b&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; M1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Apr 2022 12:36:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/mark-a-specific-combination-of-two-variables-next-to-each-other/m-p/806923#M318018</guid>
      <dc:creator>MABRINCH</dc:creator>
      <dc:date>2022-04-09T12:36:39Z</dc:date>
    </item>
    <item>
      <title>Re: mark a specific combination of two variables next to each other</title>
      <link>https://communities.sas.com/t5/SAS-Programming/mark-a-specific-combination-of-two-variables-next-to-each-other/m-p/806924#M318019</link>
      <description>&lt;P&gt;UNTESTED CODE&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    array c code_1-code_44;
    met=.;
    do i=1 to dim(c)-1;
        if c(i) in ('T1b','T4a','T3a') and c(i+1) in ('M1','M2','U3') then do;
            met=1;
            leave;
        end;
    end;
    drop i;
run;
        &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 09 Apr 2022 14:14:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/mark-a-specific-combination-of-two-variables-next-to-each-other/m-p/806924#M318019</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-04-09T14:14:33Z</dc:date>
    </item>
    <item>
      <title>Re: mark a specific combination of two variables next to each other</title>
      <link>https://communities.sas.com/t5/SAS-Programming/mark-a-specific-combination-of-two-variables-next-to-each-other/m-p/806958#M318036</link>
      <description>&lt;P&gt;This too is untested, in the absence of sample data in the form of a working data step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop=i _:);
  array search_strings {9} $8 _temporary_;
  length _part1 $3 _part2 $2  _code_string $200;

  if _n_=1 then do _part1="T1b","T4a","T3a";
    do _part2="M1","M2","U3";
      i+1;
      search_strings{i}=catx('!',_part1,_part2);
      put i=  search_strings{i}=;
    end;
  end;

  set have;
  _code_string=catx('!',of code_:);
  met=0;
  do i=1 to dim(search_strings) until (met=1);
    if findw(_code_string,trim(search_strings{i}),'!')&amp;gt;0 then met=1;
  end;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This works by forming an array of compound terms to search for - each compound term (for example "T1b!M1") formed by concatenating one of the _PART1 expressions followed by a "!" followed by one of the _PART2 expressions - nine compound expressions in your case.&amp;nbsp; The array is declared as _TEMPORARY_ meaning it will not be output, but will be retained throughout the data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then do a similar concatenation of the 44 CODE_ values, also with '!' as a separator.&amp;nbsp; Search that concatenated string for each of the 9 compound search terms until there is success, or you've exhausted the search terms.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Make sure you declare sufficient LENGTHs for the array elements and the other needed variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Apr 2022 22:44:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/mark-a-specific-combination-of-two-variables-next-to-each-other/m-p/806958#M318036</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-04-09T22:44:57Z</dc:date>
    </item>
  </channel>
</rss>

