<?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 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/If-then-statement/m-p/517845#M140077</link>
    <description>&lt;P&gt;Maxim 4: Try It.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code looks good to me.&lt;/P&gt;</description>
    <pubDate>Sun, 02 Dec 2018 09:29:18 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2018-12-02T09:29:18Z</dc:date>
    <item>
      <title>If then statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-then-statement/m-p/517842#M140075</link>
      <description>&lt;P&gt;I want to ask how to properly use if then statements.&lt;/P&gt;&lt;P&gt;lets say the variables is score.&lt;/P&gt;&lt;P&gt;score&amp;lt;50=fail_score, score 50-75=decent_score 75-100=good_score&lt;/P&gt;&lt;P&gt;What should the if statements be?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-weight: 400;"&gt;if score&amp;lt;=50 then output fail_score;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-weight: 400;"&gt;If 50&amp;gt;score&amp;lt;=75 then output decent_score;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-weight: 400;"&gt;if 75&amp;gt;score&amp;lt;=100 then output good_score?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 02 Dec 2018 08:54:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-then-statement/m-p/517842#M140075</guid>
      <dc:creator>kennyA</dc:creator>
      <dc:date>2018-12-02T08:54:17Z</dc:date>
    </item>
    <item>
      <title>Re: If then statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-then-statement/m-p/517845#M140077</link>
      <description>&lt;P&gt;Maxim 4: Try It.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code looks good to me.&lt;/P&gt;</description>
      <pubDate>Sun, 02 Dec 2018 09:29:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-then-statement/m-p/517845#M140077</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-12-02T09:29:18Z</dc:date>
    </item>
    <item>
      <title>Re: If then statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-then-statement/m-p/517846#M140078</link>
      <description>do i need to "keep fail_score decent_score good_score;" before running?</description>
      <pubDate>Sun, 02 Dec 2018 09:37:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-then-statement/m-p/517846#M140078</guid>
      <dc:creator>kennyA</dc:creator>
      <dc:date>2018-12-02T09:37:33Z</dc:date>
    </item>
    <item>
      <title>Re: If then statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/If-then-statement/m-p/517857#M140082</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/243976"&gt;@kennyA&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I want to ask how to properly use if then statements.&lt;/P&gt;
&lt;P&gt;lets say the variables is score.&lt;/P&gt;
&lt;P&gt;score&amp;lt;50=fail_score, score 50-75=decent_score 75-100=good_score&lt;/P&gt;
&lt;P&gt;What should the if statements be?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-weight: 400;"&gt;if score&amp;lt;=50 then output fail_score;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-weight: 400;"&gt;If 50&amp;gt;score&amp;lt;=75 then output decent_score;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-weight: 400;"&gt;if 75&amp;gt;score&amp;lt;=100 then output good_score?&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/243976"&gt;@kennyA&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First of all, it's advisable to check the specifications. In your example they are ambiguous regarding the classification of score=75. Let's fix this for now: score 50 - &lt;FONT color="#008000"&gt;&lt;STRONG&gt;&amp;lt;&lt;/STRONG&gt;&lt;/FONT&gt;75 = decent_score.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Typically such ranges would be dealt with from bottom to top or vice versa including ELSE statements in order to avoid typing the same boundary value twice. Always remember that in SAS an inequality like &lt;FONT face="courier new,courier"&gt;score&amp;lt;=50&lt;/FONT&gt; is not only met by &lt;FONT face="courier new,courier"&gt;score&lt;/FONT&gt; values between 0 and 50 and negative values, but also by &lt;EM&gt;missing&lt;/EM&gt; (incl. special missing) values of &lt;FONT face="courier new,courier"&gt;score&lt;/FONT&gt;. Moreover, the possibility of unexpected values (e.g. score&amp;gt;100) should be kept in mind. (In a more advanced context even the possibility of rounding errors should be considered, e.g., score=50.0000000000001 with the deviation from 50 being an artifact created by a calculation involving rounding errors, possibly due to numeric representation issues.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bottom-up approach:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if missing(score) then ...; /* equivalent: if score&amp;lt;=.z then ...; */
else if score&amp;lt;50 then ...;
else if score&amp;lt;75 then ...;
else if score&amp;lt;=100 then ...;
else ...; /* handle values &amp;gt;100 if any */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Corresponding top-down approach:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if score&amp;gt;100 then ...;
else if score&amp;gt;=75 then ...;
else if score&amp;gt;=50 then ...;
else if ~missing(score) then ...; /* equivalent: else if score&amp;gt;.z then ...; */
else ...; /* handle missing values */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(&lt;FONT face="courier new,courier"&gt;.z&lt;/FONT&gt; is the largest special missing value.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that your IF conditions are incorrect. The first doesn't match the specification for score=50 (and includes missing scores in the selection if any), the second is wrongly equivalent to &lt;FONT face="courier new,courier"&gt;score&amp;lt;50&lt;/FONT&gt; and the third to &lt;FONT face="courier new,courier"&gt;score&amp;lt;75&lt;/FONT&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also it's unclear what the actions should be: Create new variable(s)? Write something to the log? Create new datasets? ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your OUTPUT statments would be suitable for creating new datasets containing observations satisfying the respective IF conditions. In this case their names (fail_score etc.) must appear in the DATA statement of the DATA step, not in a KEEP statement.&lt;/P&gt;</description>
      <pubDate>Sun, 02 Dec 2018 14:11:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/If-then-statement/m-p/517857#M140082</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2018-12-02T14:11:11Z</dc:date>
    </item>
  </channel>
</rss>

