<?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: IF Condition in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/IF-Condition/m-p/799891#M314580</link>
    <description>&lt;P&gt;Looks right to me, except the colons after first and third "in."&lt;/P&gt;</description>
    <pubDate>Thu, 03 Mar 2022 15:55:20 GMT</pubDate>
    <dc:creator>pink_poodle</dc:creator>
    <dc:date>2022-03-03T15:55:20Z</dc:date>
    <item>
      <title>IF Condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-Condition/m-p/799868#M314564</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would appreciate some help to advice if the code below is correct to apply the type criteria to both T407 and F12 diagnoses or should the code be written in a different way&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Diag=0;

array type diag_type:;
array code diag_code:;

 do i=1 to 25;

 IF SUBSTR(code{i},1,4) in : ('T407') or SUBSTR(code{i}, 1,3) in ('F12') 
 and type{i} in: ('M', '1', '2', '3', 'W', 'X', 'Y'  '9' ) then Diag=1;

  end;

 if Diag=1  then output; ;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Thankyou&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Mar 2022 14:40:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-Condition/m-p/799868#M314564</guid>
      <dc:creator>Baba9</dc:creator>
      <dc:date>2022-03-03T14:40:24Z</dc:date>
    </item>
    <item>
      <title>Re: IF Condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-Condition/m-p/799873#M314568</link>
      <description>&lt;P&gt;Do you want up to 25 records output for if the condition is met multiple times? If you want just one record when any of those is met I might suggest:&lt;/P&gt;
&lt;P&gt;The Leave instruction will leave the do loop with the first assignment of diag.&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;Data want;
   set have;
   array type diag_type:;
    array code diag_code:;

 do i=1 to dim(type);/* use of Dim means if your data changes the number of type
                        variables the loop adjusts with the data
                     */

    IF SUBSTR(code{i},1,4) in : ('T407') or SUBSTR(code{i}, 1,3) in ('F12') 
    and type{i} in: ('M', '1', '2', '3', 'W', 'X', 'Y'  '9' ) then do;
        Diag=1;
        leave;
    end;

  end;

 if Diag=1  then output; ;

run;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Mar 2022 14:54:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-Condition/m-p/799873#M314568</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-03-03T14:54:53Z</dc:date>
    </item>
    <item>
      <title>Re: IF Condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-Condition/m-p/799876#M314570</link>
      <description>&lt;P&gt;Your IF condition might be wrong.&amp;nbsp;You have coded a boolean expression in the form of &lt;STRONG&gt;A or B and C&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you want that to be &lt;STRONG&gt;(A or B) and C&lt;/STRONG&gt;?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or do you want that to be &lt;STRONG&gt;A or (B and C)&lt;/STRONG&gt;?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Whichever it is add in the parentheses to make sure it is going to do what you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can save a little time by stopping the loop when you have found the first hit.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;diag=0;
do i=1 to 25 until(diag=1);
&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;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Mar 2022 15:08:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-Condition/m-p/799876#M314570</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-03-03T15:08:11Z</dc:date>
    </item>
    <item>
      <title>Re: IF Condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-Condition/m-p/799878#M314572</link>
      <description>IF (SUBSTR(code{i},1,4) in : ('T407') or SUBSTR(code{i}, 1,3) in ('F12')) &lt;BR /&gt; and type{i} in: ('M', '1', '2', '3', 'W', 'X', 'Y'  '9' ) then Diag=1;&lt;BR /&gt;Is the use of parenthese correct above &lt;BR /&gt;I want it to be (A or B) and C</description>
      <pubDate>Thu, 03 Mar 2022 15:15:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-Condition/m-p/799878#M314572</guid>
      <dc:creator>Baba9</dc:creator>
      <dc:date>2022-03-03T15:15:32Z</dc:date>
    </item>
    <item>
      <title>Re: IF Condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-Condition/m-p/799883#M314574</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/385462"&gt;@Baba9&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;IF (SUBSTR(code{i},1,4) in : ('T407') or SUBSTR(code{i}, 1,3) in ('F12')) &lt;BR /&gt;and type{i} in: ('M', '1', '2', '3', 'W', 'X', 'Y' '9' ) then Diag=1;&lt;BR /&gt;Is the use of parenthese correct above &lt;BR /&gt;I want it to be (A or B) and C&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Looks good.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that if you are going to use the : modifier so that the IN operator only compares up to the length of the shortest string you don't need to have the SUBSTR() functions.&amp;nbsp; You don't even really need two IN operators even though some of the codes are 3 characters and others are 4.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if code{i} in: ('T407' 'F12') and type{i} in: ('M' '1' '2' '3' 'W' 'X' 'Y' '9') then Diag=1;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 03 Mar 2022 15:29:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-Condition/m-p/799883#M314574</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-03-03T15:29:51Z</dc:date>
    </item>
    <item>
      <title>Re: IF Condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-Condition/m-p/799891#M314580</link>
      <description>&lt;P&gt;Looks right to me, except the colons after first and third "in."&lt;/P&gt;</description>
      <pubDate>Thu, 03 Mar 2022 15:55:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-Condition/m-p/799891#M314580</guid>
      <dc:creator>pink_poodle</dc:creator>
      <dc:date>2022-03-03T15:55:20Z</dc:date>
    </item>
  </channel>
</rss>

