<?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 THEN Confusion. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-Confusion/m-p/273053#M54373</link>
    <description>&lt;P&gt;This i sbecause you care comparing character variable with numerical value. This will work&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input type $ @@;
datalines;
A B
;
data next;
set have;
if  type=' ' or missing(type) then type_ind=0;
else if type='A' then type_ind=1;
else type_ind=2;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 25 May 2016 15:53:13 GMT</pubDate>
    <dc:creator>umeshMahajan</dc:creator>
    <dc:date>2016-05-25T15:53:13Z</dc:date>
    <item>
      <title>IF THEN Confusion.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-Confusion/m-p/273052#M54372</link>
      <description>&lt;P&gt;data have;&lt;BR /&gt;input type$ @@;&lt;BR /&gt;datalines;&lt;BR /&gt;A B&lt;BR /&gt;;&lt;BR /&gt;data next;&lt;BR /&gt;set have;&lt;BR /&gt;if type=. or type=' ' then type_ind=0;&lt;BR /&gt;else if type='A' then type_ind=1;&lt;BR /&gt;else type_ind=2;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;can somebody tell me whey type_ind return all 0?&lt;BR /&gt;I know remove 'type=.' will fix the problem,&lt;BR /&gt;but how that piece of code affects the results?&lt;BR /&gt;Shouldn't it be ignored in the process?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Joe&lt;/P&gt;</description>
      <pubDate>Wed, 25 May 2016 15:42:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-Confusion/m-p/273052#M54372</guid>
      <dc:creator>jiangmi</dc:creator>
      <dc:date>2016-05-25T15:42:50Z</dc:date>
    </item>
    <item>
      <title>Re: IF THEN Confusion.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-Confusion/m-p/273053#M54373</link>
      <description>&lt;P&gt;This i sbecause you care comparing character variable with numerical value. This will work&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input type $ @@;
datalines;
A B
;
data next;
set have;
if  type=' ' or missing(type) then type_ind=0;
else if type='A' then type_ind=1;
else type_ind=2;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 25 May 2016 15:53:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-Confusion/m-p/273053#M54373</guid>
      <dc:creator>umeshMahajan</dc:creator>
      <dc:date>2016-05-25T15:53:13Z</dc:date>
    </item>
    <item>
      <title>Re: IF THEN Confusion.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-Confusion/m-p/273057#M54375</link>
      <description>shouldn't SAS ignore the wrongful comparison anyway?</description>
      <pubDate>Wed, 25 May 2016 15:59:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-Confusion/m-p/273057#M54375</guid>
      <dc:creator>jiangmi</dc:creator>
      <dc:date>2016-05-25T15:59:43Z</dc:date>
    </item>
    <item>
      <title>Re: IF THEN Confusion.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-Confusion/m-p/273061#M54378</link>
      <description>&lt;P&gt;You asked SAS to convert your character variable TYPE to a number so that it could compare it the numeric missing value. Since 'A' and 'B' cannot convert to numbers&amp;nbsp;the result is a missing value. &amp;nbsp;Hence your IF condition is true. &amp;nbsp;Either&amp;nbsp;use the MISSING() function as it will handle both numeric and character values. &amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if missing(TYPE) then ...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You clearly know that TYPE is character since your other IF statements reference values like 'A', so why did you try to compare TYPE to numeric missing value? &amp;nbsp;Perhaps you do not understand how SAS stores character variables? &amp;nbsp;SAS stores character variables as fixed length strings that automatically padded on the right with spaces. &amp;nbsp;It will trim trailing spaces in most comparisons automatically and treats a values that only contains spaces the same as a missing value.&lt;/P&gt;</description>
      <pubDate>Wed, 25 May 2016 16:10:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-Confusion/m-p/273061#M54378</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-05-25T16:10:38Z</dc:date>
    </item>
    <item>
      <title>Re: IF THEN Confusion.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-Confusion/m-p/273062#M54379</link>
      <description>Thanks for the detailed explanation. &lt;BR /&gt;</description>
      <pubDate>Wed, 25 May 2016 16:13:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-Confusion/m-p/273062#M54379</guid>
      <dc:creator>jiangmi</dc:creator>
      <dc:date>2016-05-25T16:13:10Z</dc:date>
    </item>
  </channel>
</rss>

