<?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: anything wrong with the if statement or the data in the variable? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/anything-wrong-with-the-if-statement-or-the-data-in-the-variable/m-p/572628#M161614</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is nothing wrong with the code you show.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
    input ratecde $ rsktyp $;
    length cov_type $10.;

    if ratecde='1000' OR ratecde='coin' OR ratecde='' then do;

        if rsktyp in ('FHO','FHW','FHZ') then cov_type='HH';
        else if rsktyp in ('FHH','FHI','FHY') then cov_type='HO';
        else if rsktyp in ('FCL','FCZ','FLP') then cov_type='Conloss';
        else if rsktyp in ('FAZ','FDA','FIA') then cov_type='IAR';
        else if rsktyp in ('FDP','FFD','FFZ','FHX','FMD','FMP') then cov_type='MD1';

    end;

    cards;
1000 FHO
1000 FHH
1000 FCL
1000 FAZ
1000 FDP
. FHO
. FHH
. FCL
. FAZ
. FDP
coin FHO
coin FHH
coin FCL
coin FAZ
coin FDP
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Can you provide a complete runnable code (with example data in the form of a data step as above) that illustrates your problem ?&lt;/P&gt;</description>
    <pubDate>Thu, 11 Jul 2019 08:07:45 GMT</pubDate>
    <dc:creator>gamotte</dc:creator>
    <dc:date>2019-07-11T08:07:45Z</dc:date>
    <item>
      <title>anything wrong with the if statement or the data in the variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/anything-wrong-with-the-if-statement-or-the-data-in-the-variable/m-p/572626#M161613</link>
      <description>&lt;P&gt;Hi all, facing problem about the code below:. When I run it , the result only able to detect ratecde=1000 and ratecde='' (the&amp;nbsp; blank data).&lt;/P&gt;&lt;P&gt;However sas&amp;nbsp;unable to read the variable ratecde='coin'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For the variable column ratecde. There are many datas whih is including these three ---&amp;gt; 1000,coin and (blank).and other numbers&lt;/P&gt;&lt;P&gt;&amp;nbsp;I set the ratecde to be character variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Suppose with the code below, these three &lt;FONT face="Courier New" size="3"&gt;ratecde=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'1000'&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;OR&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; ratecde=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'coin'&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;OR&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; ratecde=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;''&lt;/FONT&gt; &lt;FONT face="arial,helvetica,sans-serif"&gt;will not have any results in the cov_type column. &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;ratecde='1000' and ratecde='' "&amp;nbsp; does the result I want which is without any data in cov_type&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;&lt;STRONG&gt;However ratecde='coin' have data in cov_type&amp;nbsp;&amp;nbsp; (this is wrong)&lt;/STRONG&gt;.&amp;nbsp; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;Does I type anything wrong in my code?&lt;/FONT&gt;&lt;/P&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;&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; ratecde=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'1000'&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;OR&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; ratecde=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'coin'&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;OR&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; ratecde=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;''&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;then&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;do&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;/P&gt;&lt;P&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; rsktyp in (&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'FHO'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'FHW'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'FHZ'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;then&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;cov_type=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'HH'&lt;/FONT&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;else&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; rsktyp in (&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'FHH'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'FHI'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'FHY'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;then&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;cov_type=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'HO'&lt;/FONT&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;else&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; rsktyp in (&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'FCL'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'FCZ'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'FLP'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;then&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;cov_type=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'Conloss'&lt;/FONT&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;else&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; rsktyp in (&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'FAZ'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'FDA'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'FIA'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;then&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;cov_type=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'IAR'&lt;/FONT&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;else&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; rsktyp in (&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'FDP'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'FFD'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'FFZ'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'FHX'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'FMD'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'FMP'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;then&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;cov_type=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'MD1'&lt;/FONT&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;end&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;</description>
      <pubDate>Thu, 11 Jul 2019 07:55:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/anything-wrong-with-the-if-statement-or-the-data-in-the-variable/m-p/572626#M161613</guid>
      <dc:creator>Kayla_Tan222</dc:creator>
      <dc:date>2019-07-11T07:55:01Z</dc:date>
    </item>
    <item>
      <title>Re: anything wrong with the if statement or the data in the variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/anything-wrong-with-the-if-statement-or-the-data-in-the-variable/m-p/572628#M161614</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is nothing wrong with the code you show.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
    input ratecde $ rsktyp $;
    length cov_type $10.;

    if ratecde='1000' OR ratecde='coin' OR ratecde='' then do;

        if rsktyp in ('FHO','FHW','FHZ') then cov_type='HH';
        else if rsktyp in ('FHH','FHI','FHY') then cov_type='HO';
        else if rsktyp in ('FCL','FCZ','FLP') then cov_type='Conloss';
        else if rsktyp in ('FAZ','FDA','FIA') then cov_type='IAR';
        else if rsktyp in ('FDP','FFD','FFZ','FHX','FMD','FMP') then cov_type='MD1';

    end;

    cards;
1000 FHO
1000 FHH
1000 FCL
1000 FAZ
1000 FDP
. FHO
. FHH
. FCL
. FAZ
. FDP
coin FHO
coin FHH
coin FCL
coin FAZ
coin FDP
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Can you provide a complete runnable code (with example data in the form of a data step as above) that illustrates your problem ?&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jul 2019 08:07:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/anything-wrong-with-the-if-statement-or-the-data-in-the-variable/m-p/572628#M161614</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2019-07-11T08:07:45Z</dc:date>
    </item>
    <item>
      <title>Re: anything wrong with the if statement or the data in the variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/anything-wrong-with-the-if-statement-or-the-data-in-the-variable/m-p/572636#M161616</link>
      <description>&lt;P&gt;Start by not writing ugly, unmaintainable code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if ratecde in ('1000','coin','')
then do;
  select (rsktyp);
    when ('FHO','FHW','FHZ') cov_type = 'HH';
    when ('FHH','FHI','FHY') cov_type = 'HO';
    when ('FCL','FCZ','FLP') cov_type = 'Conloss';
    when ('FAZ','FDA','FIA') cov_type = 'IAR';
    when ('FDP','FFD','FFZ','FHX','FMD','FMP') cov_type = 'MD1';
  end;
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now the visual structure of the code reflects the logic behind it, and you can make a decision where your code might not reflect your intended logic much more easily.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One thing that looks suspicious to me is not setting a length for cov_type. If&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;cov_type = 'HH';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is the first occurrence of cov_type in your code, it will be defined as $2, and longer values will be truncated. See Maxim 47.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And, of course, supply usable example data and the expected outcome from it.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jul 2019 08:31:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/anything-wrong-with-the-if-statement-or-the-data-in-the-variable/m-p/572636#M161616</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-07-11T08:31:43Z</dc:date>
    </item>
    <item>
      <title>Re: anything wrong with the if statement or the data in the variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/anything-wrong-with-the-if-statement-or-the-data-in-the-variable/m-p/572659#M161625</link>
      <description>&lt;P&gt;When you examine character values, capitalization is important.&amp;nbsp; These are all different values:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;coin&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;coin&lt;/P&gt;
&lt;P&gt;Coin&lt;/P&gt;
&lt;P&gt;COIN&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So when you look for values that match, you have to use the exact value that appears in your data.&amp;nbsp; This might be overkill, but would be safer:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;ratecde=&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#800080"&gt;'1000'&lt;/FONT&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;OR&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;SPAN&gt;&amp;nbsp;upcase(left(&lt;/SPAN&gt;ratecde))=&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#800080"&gt;'COIN'&lt;/FONT&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;OR&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;ratecde=&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#800080"&gt;''&lt;/FONT&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;then&lt;/FONT&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;do&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jul 2019 11:09:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/anything-wrong-with-the-if-statement-or-the-data-in-the-variable/m-p/572659#M161625</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-07-11T11:09:42Z</dc:date>
    </item>
  </channel>
</rss>

