<?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: Matching multiple values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Matching-multiple-values/m-p/857105#M338627</link>
    <description>I agree..   I cannot use real data.  but I discovered the problem I am having is related to the length of the data.  The codes in the real data have different lengths...  For example: KK109Y40,Y744P0,K444U7,H402O2,Y4449HH898O9,YY4930,TT785U983I9&lt;BR /&gt;&lt;BR /&gt;So in this example, the lengths are 11, 6, 12, 6, 6, 7.  So, if I leave the array like this "Array RejC{4}  $  (&amp;amp;RejCode);" it will truncate the values to the length of the first one It reads.  However, if I use the length of the longest values like this: Array RejC{4}  $12  (&amp;amp;RejCode);  it doesn't like it.  But if I use $11 instead of the longest, then it works.  Have you ever seen something like this?  Any ideas?</description>
    <pubDate>Fri, 03 Feb 2023 20:05:27 GMT</pubDate>
    <dc:creator>ismahero2</dc:creator>
    <dc:date>2023-02-03T20:05:27Z</dc:date>
    <item>
      <title>Matching multiple values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Matching-multiple-values/m-p/857088#M338614</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a list of values I need to find if any of them is present in a variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example: I have a dataset or macro variable with a list of values like this: &lt;/P&gt;
&lt;P&gt;K109Y4&lt;/P&gt;
&lt;P&gt;K509J3&lt;/P&gt;
&lt;P&gt;H402O2&lt;/P&gt;
&lt;P&gt;Y5555P3&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And I have a dataset that contains a variable named codes.&amp;nbsp; I want to know if any of those values are present in the data.&lt;/P&gt;
&lt;P&gt;OBS&amp;nbsp;&amp;nbsp;&amp;nbsp; Codes&lt;/P&gt;
&lt;P&gt;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; K109Y4,Y744P0,K444U7,H402O2&lt;/P&gt;
&lt;P&gt;&amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; K330O9,H402O2&lt;/P&gt;
&lt;P&gt;&amp;nbsp; 3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; J777R5,R555N2,P909M4&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In my results datasets, I would like to see OBS 1 and 2 because at least one of the values in my list matches the data in the string.&lt;/P&gt;
&lt;P&gt;I am thinking of using Index(Codes) but what I am struggling is creating a code that will cycle through all the values, and if it one is positive in the index() then output.&amp;nbsp; And if one of them is positive stop the loop and continue with the next record after it outputs the data.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I was trying to use an array and the leave statement after the output but is not getting me what I need.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any ideas?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%Let RejCode="K109Y4" "K509J3" "H402O2" "Y5555P3";

Data want;
Set source: ;
Array RejC{4}  $  (&amp;amp;RejCode);
Do i=1 to dim(RejC);
      if index(codes,RejC[i])&amp;gt;0 then do;&lt;BR /&gt;      Output;&lt;BR /&gt;      leave;&lt;BR /&gt;      end;&lt;BR /&gt;end; &lt;BR /&gt;end;&lt;BR /&gt;Run;&lt;BR /&gt;



&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Feb 2023 19:01:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Matching-multiple-values/m-p/857088#M338614</guid>
      <dc:creator>ismahero2</dc:creator>
      <dc:date>2023-02-03T19:01:29Z</dc:date>
    </item>
    <item>
      <title>Re: Matching multiple values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Matching-multiple-values/m-p/857091#M338617</link>
      <description>&lt;P&gt;works for me. If the same code doesn't work for you, then we are not using the same data in data set SOURCE. Or are you getting errors in the log? (which you didn't say you were).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%Let RejCode="K109Y4" "K509J3" "H402O2" "Y5555P3";

data source;
    infile cards truncover;
    input obs  codes $60.;
cards;
1 K109Y4,Y744P0,K444U7,H402O2
2 K330O9,H402O2
3 J777R5,R555N2,P909M4
;

Data want;
    set source: ;
    Array RejC{4}  $  (&amp;amp;RejCode);  
    do i=1 to dim(RejC);
        if index(codes,RejC[i])&amp;gt;0 then do;
        Output;
        leave;
        end; 
    end;
Run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Feb 2023 19:28:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Matching-multiple-values/m-p/857091#M338617</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-02-03T19:28:12Z</dc:date>
    </item>
    <item>
      <title>Re: Matching multiple values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Matching-multiple-values/m-p/857105#M338627</link>
      <description>I agree..   I cannot use real data.  but I discovered the problem I am having is related to the length of the data.  The codes in the real data have different lengths...  For example: KK109Y40,Y744P0,K444U7,H402O2,Y4449HH898O9,YY4930,TT785U983I9&lt;BR /&gt;&lt;BR /&gt;So in this example, the lengths are 11, 6, 12, 6, 6, 7.  So, if I leave the array like this "Array RejC{4}  $  (&amp;amp;RejCode);" it will truncate the values to the length of the first one It reads.  However, if I use the length of the longest values like this: Array RejC{4}  $12  (&amp;amp;RejCode);  it doesn't like it.  But if I use $11 instead of the longest, then it works.  Have you ever seen something like this?  Any ideas?</description>
      <pubDate>Fri, 03 Feb 2023 20:05:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Matching-multiple-values/m-p/857105#M338627</guid>
      <dc:creator>ismahero2</dc:creator>
      <dc:date>2023-02-03T20:05:27Z</dc:date>
    </item>
    <item>
      <title>Re: Matching multiple values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Matching-multiple-values/m-p/857106#M338628</link>
      <description>&lt;P&gt;You could use this to force all variables in the array to have length 12. Naturally, you would need to find the longest element and make sure you have use that length and not necessarily 12.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;    array rejc{4}  $12 (&amp;amp;rejcode);  
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 03 Feb 2023 20:10:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Matching-multiple-values/m-p/857106#M338628</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-02-03T20:10:43Z</dc:date>
    </item>
  </channel>
</rss>

