<?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: NOT IN statement in DO loop? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/NOT-IN-statement-in-DO-loop/m-p/375143#M89909</link>
    <description>&lt;P&gt;Works fine for me&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data TEST;
  set SASHELP.CLASS(obs=3);
  array ICD {2} NAME SEX;
  do I = 1 to 2;
    putlog _N_= I= NAME= ;
    if ICD {I} not in: ("Ali") then leave; 
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;_N_=1 i=1 Name=Alfred&lt;BR /&gt;_N_=2 i=1 Name=Alice&lt;BR /&gt;_N_=2 i=2 Name=Alice&lt;BR /&gt;_N_=3 i=1 Name=Barbara&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 11 Jul 2017 21:54:38 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2017-07-11T21:54:38Z</dc:date>
    <item>
      <title>NOT IN statement in DO loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/NOT-IN-statement-in-DO-loop/m-p/375135#M89906</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to exclude rows which has "45981" string in any of the 4 columns DX1-DX4. I used DO loop but it's not doing anything and neither throws error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA E.Val1;
SET E.Comb_1234;
ARRAY ICD {4} DX1-DX4;
	DO i = 1 to 4;
			IF ICD {i} not in: ("45981") THEN DO; 
		OUTPUT; 
		LEAVE; 
		END;
	END;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Can I use "NOT IN" in the above code?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jul 2017 21:17:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/NOT-IN-statement-in-DO-loop/m-p/375135#M89906</guid>
      <dc:creator>Sujithpeta</dc:creator>
      <dc:date>2017-07-11T21:17:30Z</dc:date>
    </item>
    <item>
      <title>Re: NOT IN statement in DO loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/NOT-IN-statement-in-DO-loop/m-p/375140#M89907</link>
      <description>&lt;P&gt;You're using the IN: which checks the beginning of the string matches. Is that what you intended to do? Otherwise I would recommend using WHICHC.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jul 2017 21:39:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/NOT-IN-statement-in-DO-loop/m-p/375140#M89907</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-07-11T21:39:18Z</dc:date>
    </item>
    <item>
      <title>Re: NOT IN statement in DO loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/NOT-IN-statement-in-DO-loop/m-p/375141#M89908</link>
      <description>&lt;P&gt;Hi, I also tried&amp;nbsp;using "NOT IN" instead "NOT IN:" it doesn't work.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jul 2017 21:44:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/NOT-IN-statement-in-DO-loop/m-p/375141#M89908</guid>
      <dc:creator>Sujithpeta</dc:creator>
      <dc:date>2017-07-11T21:44:57Z</dc:date>
    </item>
    <item>
      <title>Re: NOT IN statement in DO loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/NOT-IN-statement-in-DO-loop/m-p/375143#M89909</link>
      <description>&lt;P&gt;Works fine for me&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data TEST;
  set SASHELP.CLASS(obs=3);
  array ICD {2} NAME SEX;
  do I = 1 to 2;
    putlog _N_= I= NAME= ;
    if ICD {I} not in: ("Ali") then leave; 
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;_N_=1 i=1 Name=Alfred&lt;BR /&gt;_N_=2 i=1 Name=Alice&lt;BR /&gt;_N_=2 i=2 Name=Alice&lt;BR /&gt;_N_=3 i=1 Name=Barbara&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jul 2017 21:54:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/NOT-IN-statement-in-DO-loop/m-p/375143#M89909</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2017-07-11T21:54:38Z</dc:date>
    </item>
    <item>
      <title>Re: NOT IN statement in DO loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/NOT-IN-statement-in-DO-loop/m-p/375144#M89910</link>
      <description>&lt;P&gt;They are different comparisons.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try one of the follow methods instead:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA E.Val1;
SET E.Comb_1234;
ARRAY ICD {4} DX1-DX4;

if whichc('45981', of icd(*))&amp;gt;0 then delete;

RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA E.Val1;
SET E.Comb_1234;
ARRAY ICD {4} DX1-DX4;
flag=0;
	DO i = 1 to 4;
			IF ICD {i} in  ("45981") THEN  flag=1; 
		         if flag=1 then  LEAVE; 
		END;
	if flag=1 then delete;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jul 2017 21:54:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/NOT-IN-statement-in-DO-loop/m-p/375144#M89910</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-07-11T21:54:58Z</dc:date>
    </item>
    <item>
      <title>Re: NOT IN statement in DO loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/NOT-IN-statement-in-DO-loop/m-p/375159#M89912</link>
      <description>&lt;P&gt;Logically, your loop does the wrong thing. &amp;nbsp;If it finds the right match, it still looks through the remaining codes and outputs the observation. &amp;nbsp;So, yes, essentially it does nothing because it will output every observation unless all four of them are "45981". &amp;nbsp;Reeza has given you some ways around this, or you could use your own program and replace this part:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;
			&lt;SPAN class="token keyword"&gt;IF&lt;/SPAN&gt; ICD &lt;SPAN class="token punctuation"&gt;{&lt;/SPAN&gt;i&lt;SPAN class="token punctuation"&gt;}&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;not&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;in&lt;/SPAN&gt;: &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;"45981"&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;THEN&lt;/SPAN&gt; DO&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; 
		OUTPUT&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; 
		LEAVE&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Change it to:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if icd{i} =: "45981" then delete;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jul 2017 22:58:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/NOT-IN-statement-in-DO-loop/m-p/375159#M89912</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-07-11T22:58:29Z</dc:date>
    </item>
    <item>
      <title>Re: NOT IN statement in DO loop?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/NOT-IN-statement-in-DO-loop/m-p/375255#M89931</link>
      <description>&lt;P&gt;Something like this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; test;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;length&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; dx1-dx4 $&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;32&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; dx1-dx4;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;datalines&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;a45981 b c d&lt;/P&gt;
&lt;P&gt;a b45981 c d&lt;/P&gt;
&lt;P&gt;a b c45981 d&lt;/P&gt;
&lt;P&gt;a b c d45981&lt;/P&gt;
&lt;P&gt;a b c d&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; test2;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; test;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; prxmatch( &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'/.*45981.*/'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;, cats(OF dx1-dx4)) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;then&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; delete;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jul 2017 10:01:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/NOT-IN-statement-in-DO-loop/m-p/375255#M89931</guid>
      <dc:creator>FredrikE</dc:creator>
      <dc:date>2017-07-12T10:01:04Z</dc:date>
    </item>
  </channel>
</rss>

