<?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 statement not working consistently in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/IF-statement-not-working-consistently/m-p/979287#M378772</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;wrote:
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;IF substr(ICD10Code,1,1)=:"T21" &amp;amp; substr(ICD10Code,8,1) in ("A", "B", "C") THEN MIC=1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I assume you mean&lt;/P&gt;
&lt;PRE&gt;IF &lt;STRONG&gt;ICD10Code&lt;/STRONG&gt;=:"T21" &lt;FONT color="#999999"&gt;&amp;amp; substr(ICD10Code,8,1) in ("A", "B", "C") THEN MIC=1;&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;because&amp;nbsp;&lt;FONT face="courier new,courier"&gt;substr(ICD10Code,1,1)=:"T21"&lt;/FONT&gt; would be equivalent to&amp;nbsp;&lt;FONT face="courier new,courier"&gt;ICD10Code=:"&lt;STRONG&gt;T&lt;/STRONG&gt;"&lt;/FONT&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But&amp;nbsp;&lt;FONT face="courier new,courier"&gt;ICD10Code=:"T21"&lt;/FONT&gt; is equivalent to&amp;nbsp;&lt;SPAN&gt;&lt;FONT face="courier new,courier"&gt;substr(ICD10Code,1,3)="T21"&lt;/FONT&gt;&amp;nbsp;(assuming that &lt;FONT face="courier new,courier"&gt;ICD10Code&lt;/FONT&gt; has length &amp;gt;=3), which did not meet&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/333045"&gt;@Ihsan-Mahdi&lt;/a&gt;'s expectations.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt; So I would look at the values of&amp;nbsp;&lt;FONT face="courier new,courier"&gt;ICD10Code&lt;/FONT&gt; in &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/leforinforref/p1h8xtl50tpzthn1u8kp0sji8f60.htm" target="_blank" rel="noopener"&gt;$HEX. format&lt;/A&gt; (or use&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;'s suggestions) to find out why the IF condition is not met for a value that looks like "T21.06XA".&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 21 Nov 2025 12:38:53 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2025-11-21T12:38:53Z</dc:date>
    <item>
      <title>IF statement not working consistently</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-statement-not-working-consistently/m-p/979267#M378762</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm using this statement in my code:&lt;/P&gt;
&lt;P&gt;IF substr(ICD10Code,1,1)="T21" &amp;amp; substr(ICD10Code,8,1) in ("A", "B", "C") THEN MIC=1;&lt;/P&gt;
&lt;P&gt;However, When ICD10Code value is T21.06XA, SAS is returning MIC =0&lt;/P&gt;
&lt;P&gt;Any idea why this is happening?&lt;/P&gt;
&lt;P&gt;Thank you !&lt;/P&gt;</description>
      <pubDate>Thu, 20 Nov 2025 23:22:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-statement-not-working-consistently/m-p/979267#M378762</guid>
      <dc:creator>Ihsan-Mahdi</dc:creator>
      <dc:date>2025-11-20T23:22:30Z</dc:date>
    </item>
    <item>
      <title>Re: IF statement not working consistently</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-statement-not-working-consistently/m-p/979268#M378763</link>
      <description>&lt;P&gt;I'm sorry the correct IF statement I'm using is:&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;IF substr(ICD10Code,1,3)="T21" &amp;amp; substr(ICD10Code,8,1) in ("A", "B", "C") THEN MIC=1;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Nov 2025 23:55:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-statement-not-working-consistently/m-p/979268#M378763</guid>
      <dc:creator>Ihsan-Mahdi</dc:creator>
      <dc:date>2025-11-20T23:55:44Z</dc:date>
    </item>
    <item>
      <title>Re: IF statement not working consistently</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-statement-not-working-consistently/m-p/979269#M378764</link>
      <description>&lt;P&gt;Make sure that T21 is actually starting in the first byte of ICD10CODE.&lt;/P&gt;
&lt;P&gt;Perhaps you have leading spaces that you cannot see when you PRINT the value (especially if you use ODS printing because it removes the leading spaces).&lt;/P&gt;
&lt;P&gt;Perhaps your variable has a FORMAT attached to it that makes it PRINT something that is different than what is actually stored in the variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try printing the values using the $QUOTE. format as adding that will help with both of those potential issues.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Nov 2025 00:49:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-statement-not-working-consistently/m-p/979269#M378764</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-11-21T00:49:55Z</dc:date>
    </item>
    <item>
      <title>Re: IF statement not working consistently</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-statement-not-working-consistently/m-p/979270#M378765</link>
      <description>&lt;P&gt;If you do PROC CONTENTS on this dataset, what's the length of the ICD10 code variable?&amp;nbsp; It could be an alignment issue.&amp;nbsp; You could try:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ICD10Code=compress(ICD10code);
** and then just use your existing IF statement ;

** if that fails, just try seeing what the two substr() calls produce: ;
first3=substr(ICD10Code,1,3);
last1=substr(ICD10Code,8,1);

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could also use a picture format or regex, but might as well keep it simple.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Nov 2025 00:50:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-statement-not-working-consistently/m-p/979270#M378765</guid>
      <dc:creator>quickbluefish</dc:creator>
      <dc:date>2025-11-21T00:50:55Z</dc:date>
    </item>
    <item>
      <title>Re: IF statement not working consistently</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-statement-not-working-consistently/m-p/979276#M378769</link>
      <description>&lt;P&gt;Troubleshooting 101, print the values of your operations to the LOG.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ICD10Code_1 = substr(ICD10Code,1,1);
put ICD10Code_1=;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Alignment issues can be solved using LEFT() function.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Nov 2025 07:41:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-statement-not-working-consistently/m-p/979276#M378769</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2025-11-21T07:41:53Z</dc:date>
    </item>
    <item>
      <title>Re: IF statement not working consistently</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-statement-not-working-consistently/m-p/979279#M378771</link>
      <description>&lt;P&gt;I believe that this is what you want&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;IF substr(ICD10Code,1,1)=:"T21" &amp;amp; substr(ICD10Code,8,1) in ("A", "B", "C") THEN MIC=1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;Please note there is a colon after the equal sign; and so &lt;FONT face="courier new,courier"&gt;=:&lt;/FONT&gt; indicates&amp;nbsp;&lt;U&gt;starts with&lt;/U&gt;, which seems to be what you want.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Nov 2025 10:56:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-statement-not-working-consistently/m-p/979279#M378771</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-11-21T10:56:36Z</dc:date>
    </item>
    <item>
      <title>Re: IF statement not working consistently</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-statement-not-working-consistently/m-p/979287#M378772</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;wrote:
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;IF substr(ICD10Code,1,1)=:"T21" &amp;amp; substr(ICD10Code,8,1) in ("A", "B", "C") THEN MIC=1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I assume you mean&lt;/P&gt;
&lt;PRE&gt;IF &lt;STRONG&gt;ICD10Code&lt;/STRONG&gt;=:"T21" &lt;FONT color="#999999"&gt;&amp;amp; substr(ICD10Code,8,1) in ("A", "B", "C") THEN MIC=1;&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;because&amp;nbsp;&lt;FONT face="courier new,courier"&gt;substr(ICD10Code,1,1)=:"T21"&lt;/FONT&gt; would be equivalent to&amp;nbsp;&lt;FONT face="courier new,courier"&gt;ICD10Code=:"&lt;STRONG&gt;T&lt;/STRONG&gt;"&lt;/FONT&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But&amp;nbsp;&lt;FONT face="courier new,courier"&gt;ICD10Code=:"T21"&lt;/FONT&gt; is equivalent to&amp;nbsp;&lt;SPAN&gt;&lt;FONT face="courier new,courier"&gt;substr(ICD10Code,1,3)="T21"&lt;/FONT&gt;&amp;nbsp;(assuming that &lt;FONT face="courier new,courier"&gt;ICD10Code&lt;/FONT&gt; has length &amp;gt;=3), which did not meet&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/333045"&gt;@Ihsan-Mahdi&lt;/a&gt;'s expectations.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt; So I would look at the values of&amp;nbsp;&lt;FONT face="courier new,courier"&gt;ICD10Code&lt;/FONT&gt; in &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/leforinforref/p1h8xtl50tpzthn1u8kp0sji8f60.htm" target="_blank" rel="noopener"&gt;$HEX. format&lt;/A&gt; (or use&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;'s suggestions) to find out why the IF condition is not met for a value that looks like "T21.06XA".&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Nov 2025 12:38:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-statement-not-working-consistently/m-p/979287#M378772</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2025-11-21T12:38:53Z</dc:date>
    </item>
    <item>
      <title>Re: IF statement not working consistently</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-statement-not-working-consistently/m-p/979289#M378773</link>
      <description>&lt;P&gt;You've got some good recommendations already.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could also add a PUT statement to show the values of ICD10Code and Mic.&amp;nbsp; If the PUT statement does not execute, that means you don't actually have the value T21.06XA in your data (maybe there are leading spaces, or capitalization issues, or... )&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  set have ;
  IF substr(ICD10Code,1,3)="T21" &amp;amp; substr(ICD10Code,8,1) in ("A", "B", "C") THEN MIC=1;
  IF ICD10Code="T21.06XA" then put ICD10Code= Mic= ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And of course it always helps to look at your data:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=have ;
  tables ICD10Code*Mic/missing list ;
  format _all_ ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The IF statement you posted works, so it's likely that the value of ICD10Code is not matching your expectation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;1    data have ;
2      ICD10Code="T21.06XA" ;
3    run ;

NOTE: The data set WORK.HAVE has 1 observations and 1 variables.

4
5    data want ;
6      set have ;
7      IF substr(ICD10Code,1,3)="T21" &amp;amp; substr(ICD10Code,8,1) in ("A", "B", "C") THEN MIC=1;
8      IF ICD10Code="T21.06XA" then put ICD10Code= Mic= ;
9    run ;

ICD10Code=T21.06XA MIC=1
NOTE: There were 1 observations read from the data set WORK.HAVE.
NOTE: The data set WORK.WANT has 1 observations and 2 variables.
&lt;/PRE&gt;</description>
      <pubDate>Fri, 21 Nov 2025 13:18:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-statement-not-working-consistently/m-p/979289#M378773</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2025-11-21T13:18:54Z</dc:date>
    </item>
    <item>
      <title>Re: IF statement not working consistently</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-statement-not-working-consistently/m-p/979331#M378778</link>
      <description>&lt;P&gt;Assign a $HEX format of suitable length (double the defined length of the variable) and look at the hex codes. This will give you an idea of what is really stored there (leading blanks, possible UTF characters, non-printable characters).&lt;/P&gt;</description>
      <pubDate>Fri, 21 Nov 2025 17:55:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-statement-not-working-consistently/m-p/979331#M378778</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2025-11-21T17:55:40Z</dc:date>
    </item>
    <item>
      <title>Re: IF statement not working consistently</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-statement-not-working-consistently/m-p/979357#M378780</link>
      <description>&lt;P&gt;Yes, thank you for the clarification &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;, you are correct.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Nov 2025 22:47:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-statement-not-working-consistently/m-p/979357#M378780</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-11-21T22:47:34Z</dc:date>
    </item>
  </channel>
</rss>

