<?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: Comparing multiple columns using if-statements in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Comparing-multiple-columns-using-if-statements/m-p/344284#M273007</link>
    <description>&lt;P&gt;You could use an array to make the coding easier.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data hosp_prac;
  set hosp;
  array dx diagx1 - diagx25 ;
  found=0;
  do i=1 to dim(dx) while (found=0) ;
    found = dx(i) in ('NN1','NN2', ...... ) ;
  end;
  if found ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 25 Mar 2017 12:28:03 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2017-03-25T12:28:03Z</dc:date>
    <item>
      <title>Comparing multiple columns using if-statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-multiple-columns-using-if-statements/m-p/344282#M273006</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My dataframe consists of many rows and 25 columns sequentially labeled 'diagx1' to 'diagx25'. Each row represents an individual presenting with one or more&amp;nbsp;health conditions (diagx). There are many different conditions (10,000+), though some are more common than others. Multiple individuals can have the same condition.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wish to narrow my dataframe down to 20 conditions: if any individual has one of these conditions in 'diagx1' to 'diagx25', I want them to remain in my dataframe. I have considered using multiple if statements, though I was wondering if someone had a more elegant solution.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;For example, say the 10 conditions were: NN1, NN2, NN3, QQ1, QQ2, QQ3, OO1, OO2, OO3, V1, V2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data hosp_prac;&lt;/P&gt;&lt;P&gt;set hosp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;if diagx1 = NN1 or diagx1 = NN2 or diagx1 = NN3...&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; or diagx2 = NN1 or diagx2 = NN2 or diagx2 = NN3...&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; or diagx3 = NN1 or diagx3 = NN2...&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;....then output;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be greatly appreciated! I hope its clear enough - this is my first time posting - I'm not even sure if this belongs in this location.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Sat, 25 Mar 2017 10:42:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-multiple-columns-using-if-statements/m-p/344282#M273006</guid>
      <dc:creator>jhsaunde</dc:creator>
      <dc:date>2017-03-25T10:42:25Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing multiple columns using if-statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-multiple-columns-using-if-statements/m-p/344284#M273007</link>
      <description>&lt;P&gt;You could use an array to make the coding easier.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data hosp_prac;
  set hosp;
  array dx diagx1 - diagx25 ;
  found=0;
  do i=1 to dim(dx) while (found=0) ;
    found = dx(i) in ('NN1','NN2', ...... ) ;
  end;
  if found ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 25 Mar 2017 12:28:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-multiple-columns-using-if-statements/m-p/344284#M273007</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-03-25T12:28:03Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing multiple columns using if-statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-multiple-columns-using-if-statements/m-p/344292#M273008</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;I like the previous post better, but this is interesting

* create one ob where diag1-diag30 = NN1-NN30
data have;
  array diags[30] $3 diag1-diag30 (%macro gg;%do i=1 %to 30; "NN&amp;amp;i" %end;%mend;%gg);
run;quit;

* check for NN;
data want;
  set have;
  if index(catx(' ',of diag:),'NN');
run;quit;

1 ob written

* if you want  the postion of NN5;
data want;
  set have;
  array diags[30] $3 diag1-diag30 ;
  position = whichc('NN5',of diags[*]);
  put position;
run;quit;

5

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 25 Mar 2017 13:14:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-multiple-columns-using-if-statements/m-p/344292#M273008</guid>
      <dc:creator>rogerjdeangelis</dc:creator>
      <dc:date>2017-03-25T13:14:14Z</dc:date>
    </item>
    <item>
      <title>Re: Comparing multiple columns using if-statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparing-multiple-columns-using-if-statements/m-p/344293#M273009</link>
      <description>You can also do this&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt;  retain MaxPos;&lt;BR /&gt;  set have;&lt;BR /&gt;  array x[5];&lt;BR /&gt;  MaxPos = whichn(max(of x[*]),of x[*]);&lt;BR /&gt;run;&lt;BR /&gt;</description>
      <pubDate>Sat, 25 Mar 2017 13:15:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparing-multiple-columns-using-if-statements/m-p/344293#M273009</guid>
      <dc:creator>rogerjdeangelis</dc:creator>
      <dc:date>2017-03-25T13:15:40Z</dc:date>
    </item>
  </channel>
</rss>

