<?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: Searching through multiple variables with array not giving same results as variable-by-variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Searching-through-multiple-variables-with-array-not-giving-same/m-p/893047#M352766</link>
    <description>&lt;P&gt;An alternate:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;ARRAY dx_codes DX1-DX15;

PTB_birth_array=0;

do index=1 to dim(dx_codes ); 
    IF dx_codes[index] in: (&amp;amp;PTB_all_list.) THEN do;
         PTB_birth_array=1; 
         leave;
    end;
end;&lt;/PRE&gt;
&lt;P&gt;The Leave instruction will terminate the checking after finding the first match.&amp;nbsp; This might be useful as the Index value will be that of the Dx_codes array element that was first found in the list, potentially very useful if there is some order to the list.&lt;/P&gt;</description>
    <pubDate>Wed, 06 Sep 2023 20:54:51 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2023-09-06T20:54:51Z</dc:date>
    <item>
      <title>Searching through multiple variables with array not giving same results as variable-by-variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Searching-through-multiple-variables-with-array-not-giving-same/m-p/893026#M352761</link>
      <description>&lt;P&gt;I have a list of diagnosis codes, and I want to flag if any of those codes exist anywhere in 15 different diagnosis variables. I created a series of IF-THEN statements, but I have many such lists of DX codes and an array is a more efficient approach. However, the array is only flagging a very small percentage of cases that should be flagged (I confirmed this by manually searching the data file). The cases that it does flag hit on various DX variables (DX1, DX3, DX12, etc), so it's not like the array is only searching DX15 or something like that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let PTB_all_list = ("O6010X","O6012X","Z3A22","Z3A23","Z3A24","Z3A25","Z3A26","Z3A27","O6013X",
					 "O6014X","Z3A28","Z3A29","Z3A30","Z3A31","Z3A32","Z3A33","Z3A34","Z3A35",
					 "Z3A36");
					 
DATA want; SET have;

ARRAY dx_codes DX1-DX15;
  do index=1 to dim(dx_codes ); 
IF dx_codes[index] in: (&amp;amp;PTB_all_list.) THEN PTB_birth_array=1; ELSE PTB_birth_array=0;
end;

IF (DX1 in (&amp;amp;PTB_all_list.) OR 
	DX2 in (&amp;amp;PTB_all_list.) OR
	DX3 in (&amp;amp;PTB_all_list.) OR
	DX4 in (&amp;amp;PTB_all_list.) OR
	DX5 in (&amp;amp;PTB_all_list.) OR
	DX6 in (&amp;amp;PTB_all_list.) OR
	DX7 in (&amp;amp;PTB_all_list.) OR
	DX8 in (&amp;amp;PTB_all_list.) OR
	DX9 in (&amp;amp;PTB_all_list.) OR
	DX10 in (&amp;amp;PTB_all_list.) OR
	DX11 in (&amp;amp;PTB_all_list.) OR
	DX12 in (&amp;amp;PTB_all_list.) OR
	DX13 in (&amp;amp;PTB_all_list.) OR
	DX14 in (&amp;amp;PTB_all_list.) OR
	DX15 in (&amp;amp;PTB_all_list.)) THEN PTB_birth_line=1; ELSE PTB_birth_line=0;
RUN;

title1 "PTB";
PROC FREQ data=want;
	TABLES PTB_birth_array PTB_birth_line; RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And here are the frequencies:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Wolverine_0-1694027118963.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/87677i6251B6DAE412944B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Wolverine_0-1694027118963.png" alt="Wolverine_0-1694027118963.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Sep 2023 19:05:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Searching-through-multiple-variables-with-array-not-giving-same/m-p/893026#M352761</guid>
      <dc:creator>Wolverine</dc:creator>
      <dc:date>2023-09-06T19:05:50Z</dc:date>
    </item>
    <item>
      <title>Re: Searching through multiple variables with array not giving same results as variable-by-variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Searching-through-multiple-variables-with-array-not-giving-same/m-p/893027#M352762</link>
      <description>&lt;P&gt;Array code is incorrect, should be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ARRAY dx_codes DX1-DX15;

PTB_birth_array=0;

do index=1 to dim(dx_codes ); 
    IF dx_codes[index] in: (&amp;amp;PTB_all_list.) THEN PTB_birth_array=1; 
end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Sep 2023 19:10:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Searching-through-multiple-variables-with-array-not-giving-same/m-p/893027#M352762</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-09-06T19:10:24Z</dc:date>
    </item>
    <item>
      <title>Re: Searching through multiple variables with array not giving same results as variable-by-variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Searching-through-multiple-variables-with-array-not-giving-same/m-p/893036#M352764</link>
      <description>Okay, I see it now. If the last variable in the array (DX15) matches the codes in the PTB list, the flag is set to 1. But if DX15 does not match, the flag is set to 0 even if the previous DX vars had already set it to 1.</description>
      <pubDate>Wed, 06 Sep 2023 19:28:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Searching-through-multiple-variables-with-array-not-giving-same/m-p/893036#M352764</guid>
      <dc:creator>Wolverine</dc:creator>
      <dc:date>2023-09-06T19:28:47Z</dc:date>
    </item>
    <item>
      <title>Re: Searching through multiple variables with array not giving same results as variable-by-variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Searching-through-multiple-variables-with-array-not-giving-same/m-p/893047#M352766</link>
      <description>&lt;P&gt;An alternate:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;ARRAY dx_codes DX1-DX15;

PTB_birth_array=0;

do index=1 to dim(dx_codes ); 
    IF dx_codes[index] in: (&amp;amp;PTB_all_list.) THEN do;
         PTB_birth_array=1; 
         leave;
    end;
end;&lt;/PRE&gt;
&lt;P&gt;The Leave instruction will terminate the checking after finding the first match.&amp;nbsp; This might be useful as the Index value will be that of the Dx_codes array element that was first found in the list, potentially very useful if there is some order to the list.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Sep 2023 20:54:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Searching-through-multiple-variables-with-array-not-giving-same/m-p/893047#M352766</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-09-06T20:54:51Z</dc:date>
    </item>
  </channel>
</rss>

