<?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 Statement Not Working Properly in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/IF-Then-Statement-Not-Working-Properly/m-p/733982#M28603</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/295349"&gt;@K_Wils15&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi. I was wondering if someone could help me with my code. Here it is:&lt;/P&gt;
&lt;P&gt;data 6;&lt;BR /&gt;set 5;&lt;BR /&gt;if Q34 = "White" then Race = 1;&lt;BR /&gt;if Q34 = "Black or African American" then Race = 2;&lt;BR /&gt;if Q34 = "Asian" then Race = 3;&lt;BR /&gt;Else Race = 4;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;However, in the proc print, I have noticed it does not work correctly as you can see here:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="K_Wils15_0-1618435940569.png" style="width: 601px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/57744iF2DF7FF383D962B3/image-dimensions/601x77?v=v2" width="601" height="77" role="button" title="K_Wils15_0-1618435940569.png" alt="K_Wils15_0-1618435940569.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;White should be 1 under race but it comes up as 4, do you know why this is?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The Else as you have written the code only applies to the Q34="Asian". So when Q34="White" the Else is executed instead of the assignment of 3.&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/223452"&gt;@r_behata&lt;/a&gt; has the correct approach for the If/then/else structure. I'm just providing some detail as to why your code was wonky.&lt;/P&gt;</description>
    <pubDate>Wed, 14 Apr 2021 22:02:54 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2021-04-14T22:02:54Z</dc:date>
    <item>
      <title>IF Then Statement Not Working Properly</title>
      <link>https://communities.sas.com/t5/New-SAS-User/IF-Then-Statement-Not-Working-Properly/m-p/733963#M28597</link>
      <description>&lt;P&gt;Hi. I was wondering if someone could help me with my code. Here it is:&lt;/P&gt;
&lt;P&gt;data 6;&lt;BR /&gt;set 5;&lt;BR /&gt;if Q34 = "White" then Race = 1;&lt;BR /&gt;if Q34 = "Black or African American" then Race = 2;&lt;BR /&gt;if Q34 = "Asian" then Race = 3;&lt;BR /&gt;Else Race = 4;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;However, in the proc print, I have noticed it does not work correctly as you can see here:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;White should be 1 under race but it comes up as 4, do you know why this is?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Apr 2021 04:13:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/IF-Then-Statement-Not-Working-Properly/m-p/733963#M28597</guid>
      <dc:creator>K_Wils15</dc:creator>
      <dc:date>2021-04-15T04:13:05Z</dc:date>
    </item>
    <item>
      <title>Re: IF Then Statement Not Working Properly</title>
      <link>https://communities.sas.com/t5/New-SAS-User/IF-Then-Statement-Not-Working-Properly/m-p/733976#M28599</link>
      <description>&lt;P&gt;Your If conditions need to be mutually exclusive. Try.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if Q34 = "White" then Race = 1;
else if Q34 = "Black or African American" then Race = 2;
else if Q34 = "Asian" then Race = 3;
Else Race = 4;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Btw, 5 and 6 are not valid names for the sas datasets.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Apr 2021 21:56:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/IF-Then-Statement-Not-Working-Properly/m-p/733976#M28599</guid>
      <dc:creator>r_behata</dc:creator>
      <dc:date>2021-04-14T21:56:27Z</dc:date>
    </item>
    <item>
      <title>Re: IF Then Statement Not Working Properly</title>
      <link>https://communities.sas.com/t5/New-SAS-User/IF-Then-Statement-Not-Working-Properly/m-p/733982#M28603</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/295349"&gt;@K_Wils15&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi. I was wondering if someone could help me with my code. Here it is:&lt;/P&gt;
&lt;P&gt;data 6;&lt;BR /&gt;set 5;&lt;BR /&gt;if Q34 = "White" then Race = 1;&lt;BR /&gt;if Q34 = "Black or African American" then Race = 2;&lt;BR /&gt;if Q34 = "Asian" then Race = 3;&lt;BR /&gt;Else Race = 4;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;However, in the proc print, I have noticed it does not work correctly as you can see here:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="K_Wils15_0-1618435940569.png" style="width: 601px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/57744iF2DF7FF383D962B3/image-dimensions/601x77?v=v2" width="601" height="77" role="button" title="K_Wils15_0-1618435940569.png" alt="K_Wils15_0-1618435940569.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;White should be 1 under race but it comes up as 4, do you know why this is?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The Else as you have written the code only applies to the Q34="Asian". So when Q34="White" the Else is executed instead of the assignment of 3.&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/223452"&gt;@r_behata&lt;/a&gt; has the correct approach for the If/then/else structure. I'm just providing some detail as to why your code was wonky.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Apr 2021 22:02:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/IF-Then-Statement-Not-Working-Properly/m-p/733982#M28603</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-04-14T22:02:54Z</dc:date>
    </item>
    <item>
      <title>Re: IF Then Statement Not Working Properly</title>
      <link>https://communities.sas.com/t5/New-SAS-User/IF-Then-Statement-Not-Working-Properly/m-p/733995#M28608</link>
      <description>&lt;P&gt;Both replies are of course correct. In general, you will find that standard parts of SAS that have been successfully used for decades, ALWAYS work properly. If you are not getting the results you expect, it is a user error not a SAS error.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Apr 2021 23:33:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/IF-Then-Statement-Not-Working-Properly/m-p/733995#M28608</guid>
      <dc:creator>WarrenKuhfeld</dc:creator>
      <dc:date>2021-04-14T23:33:28Z</dc:date>
    </item>
    <item>
      <title>Re: IF Then Statement Not Working Properly</title>
      <link>https://communities.sas.com/t5/New-SAS-User/IF-Then-Statement-Not-Working-Properly/m-p/734082#M28610</link>
      <description>Thank you! Thanks for catching that, I just deleted the first part of the name because I named it after the survey. Thank you.</description>
      <pubDate>Thu, 15 Apr 2021 03:35:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/IF-Then-Statement-Not-Working-Properly/m-p/734082#M28610</guid>
      <dc:creator>K_Wils15</dc:creator>
      <dc:date>2021-04-15T03:35:35Z</dc:date>
    </item>
    <item>
      <title>Re: IF Then Statement Not Working Properly</title>
      <link>https://communities.sas.com/t5/New-SAS-User/IF-Then-Statement-Not-Working-Properly/m-p/734083#M28611</link>
      <description>Thank you for explaining!</description>
      <pubDate>Thu, 15 Apr 2021 03:36:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/IF-Then-Statement-Not-Working-Properly/m-p/734083#M28611</guid>
      <dc:creator>K_Wils15</dc:creator>
      <dc:date>2021-04-15T03:36:22Z</dc:date>
    </item>
    <item>
      <title>Re: IF Then Statement Not Working Properly</title>
      <link>https://communities.sas.com/t5/New-SAS-User/IF-Then-Statement-Not-Working-Properly/m-p/734084#M28612</link>
      <description>Got it! Thanks Warren!</description>
      <pubDate>Thu, 15 Apr 2021 03:37:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/IF-Then-Statement-Not-Working-Properly/m-p/734084#M28612</guid>
      <dc:creator>K_Wils15</dc:creator>
      <dc:date>2021-04-15T03:37:59Z</dc:date>
    </item>
  </channel>
</rss>

