<?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 Help with if then statement in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Help-with-if-then-statement/m-p/651188#M22363</link>
    <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am having trouble with this basic if then statement. I am trying to sort the table into 4 different categories but when I run this piece of code the whole capacity_label column has 4s in it even though not all the capacity variables are &amp;lt;25. Do I need to change my syntax?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data in_capacity2;&lt;BR /&gt;set in_capacity;&lt;BR /&gt;if Capacity &amp;gt; 80 then Capacity_label=1;&lt;BR /&gt;if 50 &amp;gt;Capacity &amp;gt; 79 then Capacity_label=2;&lt;BR /&gt;if 25 &amp;gt;Capacity &amp;gt; 49 then Capacity_label=3;&lt;BR /&gt;if Capacity &amp;lt;25 then Capacity_label=4;&lt;BR /&gt;run;&lt;/P&gt;</description>
    <pubDate>Wed, 27 May 2020 19:29:56 GMT</pubDate>
    <dc:creator>marleeakerson</dc:creator>
    <dc:date>2020-05-27T19:29:56Z</dc:date>
    <item>
      <title>Help with if then statement</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Help-with-if-then-statement/m-p/651188#M22363</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am having trouble with this basic if then statement. I am trying to sort the table into 4 different categories but when I run this piece of code the whole capacity_label column has 4s in it even though not all the capacity variables are &amp;lt;25. Do I need to change my syntax?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data in_capacity2;&lt;BR /&gt;set in_capacity;&lt;BR /&gt;if Capacity &amp;gt; 80 then Capacity_label=1;&lt;BR /&gt;if 50 &amp;gt;Capacity &amp;gt; 79 then Capacity_label=2;&lt;BR /&gt;if 25 &amp;gt;Capacity &amp;gt; 49 then Capacity_label=3;&lt;BR /&gt;if Capacity &amp;lt;25 then Capacity_label=4;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 27 May 2020 19:29:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Help-with-if-then-statement/m-p/651188#M22363</guid>
      <dc:creator>marleeakerson</dc:creator>
      <dc:date>2020-05-27T19:29:56Z</dc:date>
    </item>
    <item>
      <title>Re: Help with if then statement</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Help-with-if-then-statement/m-p/651192#M22365</link>
      <description>&lt;P&gt;Is your variable spelled correctly?&lt;/P&gt;
&lt;P&gt;Please post your log.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or try the following and see what happens.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data in_capacity2;
set in_capacity;
if capacity = . then capacity_label = -99;
else if Capacity &amp;gt; 80 then Capacity_label=1;
else if 50 &amp;gt;Capacity &amp;gt; 79 then Capacity_label=2;
else if 25 &amp;gt;Capacity &amp;gt; 49 then Capacity_label=3;
else if Capacity &amp;lt;25 then Capacity_label=4;
run;

proc freq data=in_capacity2;
table capacity*capacity_label/missing;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 May 2020 19:46:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Help-with-if-then-statement/m-p/651192#M22365</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-05-27T19:46:26Z</dc:date>
    </item>
    <item>
      <title>Re: Help with if then statement</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Help-with-if-then-statement/m-p/651194#M22366</link>
      <description>&lt;P&gt;One problem in your code is the following:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if 50 &amp;gt;Capacity &amp;gt; 79 then Capacity_label=2;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Is it possible for 50 to be greater than Capacity and simultaneously Capacity to be greater than 79? Yes or no? Why or why not?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Without having your data, I would re-write the whole thing as:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data in_capacity2;
set in_capacity;
if capacity &amp;gt; 80 then Capacity_label=1;
else if capacity&amp;gt;50 then Capacity_label=2;
else if capacity&amp;gt;25 then Capacity_label=3;
else Capacity_label=4;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If that doesn't work for you, then you need to show us (a portion of) your data.&lt;/P&gt;</description>
      <pubDate>Wed, 27 May 2020 19:50:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Help-with-if-then-statement/m-p/651194#M22366</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-05-27T19:50:17Z</dc:date>
    </item>
    <item>
      <title>Re: Help with if then statement</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Help-with-if-then-statement/m-p/651195#M22367</link>
      <description>&lt;P&gt;The code can be improved, but it will only assign ALL of the observations a CAPACITY_LABEL value of 4 if the CAPACITY variable is always less than 25.&amp;nbsp; Note that includes any observations where the value of CAPACITY is missing because SAS considers all of the 28 possible missing values as less than actual number.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should add ELSE's to your string of IF/THEN so it doesn't have to keep testing once it finds a match.&lt;/P&gt;
&lt;P&gt;You should make sure the tests aren't tautologies.&amp;nbsp; There is no number that is both less than 50 and greater than 79.&lt;/P&gt;
&lt;P&gt;Make sure to include the boundary values into one of the two adjacent categories.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data in_capacity2;
  set in_capacity;
  if Capacity &amp;gt; 80 then Capacity_label=1;
  else if 50 &amp;lt; Capacity &amp;lt;= 80 then Capacity_label=2;
  else if 25 &amp;lt; Capacity &amp;lt;= 50 then Capacity_label=3;
  else if missing(Capacity) then Capacity_label=.;
  else Capacity_label=4;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 May 2020 19:52:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Help-with-if-then-statement/m-p/651195#M22367</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-05-27T19:52:46Z</dc:date>
    </item>
    <item>
      <title>Re: Help with if then statement</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Help-with-if-then-statement/m-p/651200#M22368</link>
      <description>&lt;P&gt;A condition like this can never be true:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if 50 &amp;gt;Capacity &amp;gt; 79 &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If capacity is smaller than 50, it can't be greater than 79, and vice versa.&lt;/P&gt;</description>
      <pubDate>Wed, 27 May 2020 19:55:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Help-with-if-then-statement/m-p/651200#M22368</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-05-27T19:55:15Z</dc:date>
    </item>
  </channel>
</rss>

