<?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: Conditional processing with many conditions (if then else, or an array) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Conditional-processing-with-many-conditions-if-then-else-or-an/m-p/236157#M43250</link>
    <description>&lt;P&gt;Just to add, with a do loop over your codes, you don't need all the conditional code either:&lt;/P&gt;
&lt;PRE&gt;data have;
  infile datalines;
  input medication1-medication5;
datalines;
258 34 45 12 67
56 78 45 23 12
78 76 75 225 5
;
run;

data want;
  set have;
  array med{5} medication1-medication5;
  c=1;
  do i=258,225,657,234,123,897,445;
    if whichn(i,of med(*))&amp;gt;0 then code=c;
    c=c+1;
  end;
run;&lt;/PRE&gt;</description>
    <pubDate>Tue, 24 Nov 2015 09:55:03 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2015-11-24T09:55:03Z</dc:date>
    <item>
      <title>Conditional processing with many conditions (if then else, or an array)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-processing-with-many-conditions-if-then-else-or-an/m-p/236103#M43230</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need help with some code using either if, then, else, or an array.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a data set with many medication fields (wide data set). They are labeled medication1-medication29. I want to create a new variable called "code" that is equal to 1, if any of the 29 medications = 258. Then if medications =225 or 265 then code =2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is some sample code I was playing with:&lt;/P&gt;
&lt;P&gt;if (medication1 or medication2 or medication3 or medication4 or medication5...medication29)=258 then code=1;&lt;/P&gt;
&lt;P&gt;else if (medication1 or medication2 or medication3 or medication4 or medication5...medication29)=225 or (medication1 or medication2 or medication3 or medication4 or medication5...medication29)=265 then code=2;&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;P&gt;Sarah&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Nov 2015 21:34:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-processing-with-many-conditions-if-then-else-or-an/m-p/236103#M43230</guid>
      <dc:creator>sarahsasuser</dc:creator>
      <dc:date>2015-11-23T21:34:53Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional processing with many conditions (if then else, or an array)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-processing-with-many-conditions-if-then-else-or-an/m-p/236105#M43232</link>
      <description>&lt;P&gt;Look up the WHICHN or WHICHC functions depending on if your variable is character or numeric. &lt;BR /&gt;&lt;BR /&gt;Assuming Numeric:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array med(29) medication1-medication29;

if whichn(258, of med(*))&amp;gt;0 then code=1;
else if (whichn(225, of med(*))&amp;gt;0 OR whichn(265, of med(*))&amp;gt;0) then code=2;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 23 Nov 2015 21:41:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-processing-with-many-conditions-if-then-else-or-an/m-p/236105#M43232</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-11-23T21:41:51Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional processing with many conditions (if then else, or an array)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-processing-with-many-conditions-if-then-else-or-an/m-p/236157#M43250</link>
      <description>&lt;P&gt;Just to add, with a do loop over your codes, you don't need all the conditional code either:&lt;/P&gt;
&lt;PRE&gt;data have;
  infile datalines;
  input medication1-medication5;
datalines;
258 34 45 12 67
56 78 45 23 12
78 76 75 225 5
;
run;

data want;
  set have;
  array med{5} medication1-medication5;
  c=1;
  do i=258,225,657,234,123,897,445;
    if whichn(i,of med(*))&amp;gt;0 then code=c;
    c=c+1;
  end;
run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 24 Nov 2015 09:55:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-processing-with-many-conditions-if-then-else-or-an/m-p/236157#M43250</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-11-24T09:55:03Z</dc:date>
    </item>
  </channel>
</rss>

