<?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: Calculations in IF THEN statements in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Calculations-in-IF-THEN-statements/m-p/493807#M129995</link>
    <description>&lt;P&gt;Why not just restructure your logic to make it easier to determine?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data b;
  set a;
  heightin = height/ 2.54;
  IBW = .;
  if  sex='F' then do;
    if missing(heightin) then put 'Missing heightin' ;
    else if heightin lt 60 then IBW = (45 - (60- (heightin*2.3)));
    else IBW = (45 + ((heightin-60)*2.3));
  end;
  else if sex='M' then do;
    if missing(heightin) then put 'Missing heightin';
    else if heightin lt 60 then IBW = (50 - (60- (heightin*2.3)));
    else IBW = (50 + ((heightin-60)*2.3));
  end;
  else put 'Unknown SEX' sex=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 08 Sep 2018 18:17:38 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2018-09-08T18:17:38Z</dc:date>
    <item>
      <title>Calculations in IF THEN statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculations-in-IF-THEN-statements/m-p/493800#M129989</link>
      <description>&lt;P&gt;I have a simple question that I can't seem to answer.&lt;/P&gt;&lt;P&gt;I want to create and calculate a new variable IBW using 4 different equations.&lt;/P&gt;&lt;P&gt;Choice of equations depends on 2&amp;nbsp;other variables 1) sex and 2)&amp;nbsp;heightin (categorized as less than or greater or equal to 60)&lt;/P&gt;&lt;P&gt;When I use the following code, the variable IBW is generated but the calculation is not performed (value is missing for all observations) without an error message.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data b;
	set a;
	heightin = height/ 2.54;
	IBW = .;
	if sex = 'F' and heightin lt 60 then IBW = (45 - (60- (heightin*2.3)));
	if sex = 'F' and heightin ge 60 then IBW = (45 + ((heightin-60)*2.3));
	if sex = 'M' and heightin lt 60 then IBW = (50 - (60- (heightin*2.3)));
	if sex = 'M' and heightin ge 60 then IBW = (50 + ((heightin-60)*2.3));
run;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 08 Sep 2018 17:47:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculations-in-IF-THEN-statements/m-p/493800#M129989</guid>
      <dc:creator>NYSAS</dc:creator>
      <dc:date>2018-09-08T17:47:13Z</dc:date>
    </item>
    <item>
      <title>Re: Calculations in IF THEN statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculations-in-IF-THEN-statements/m-p/493803#M129992</link>
      <description>&lt;P&gt;If IBW is always missing then for each record&amp;nbsp;(1) height is missing and/or (2) sex is not 'M' or 'F'.&amp;nbsp;&amp;nbsp;If height is missing, then the statement "heightin=height/2.54;" would generate an error message on your log, and result in missing value for heightin, consequently IBW.&amp;nbsp;&amp;nbsp; But if sex in not 'M' or 'F' then there would be no error message, but missing values for IBW.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So what does you log say?&amp;nbsp; If no error message then height is never missing.&amp;nbsp; In that case you should examine the values of SEX.&lt;/P&gt;</description>
      <pubDate>Sat, 08 Sep 2018 18:00:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculations-in-IF-THEN-statements/m-p/493803#M129992</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-09-08T18:00:17Z</dc:date>
    </item>
    <item>
      <title>Re: Calculations in IF THEN statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculations-in-IF-THEN-statements/m-p/493807#M129995</link>
      <description>&lt;P&gt;Why not just restructure your logic to make it easier to determine?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data b;
  set a;
  heightin = height/ 2.54;
  IBW = .;
  if  sex='F' then do;
    if missing(heightin) then put 'Missing heightin' ;
    else if heightin lt 60 then IBW = (45 - (60- (heightin*2.3)));
    else IBW = (45 + ((heightin-60)*2.3));
  end;
  else if sex='M' then do;
    if missing(heightin) then put 'Missing heightin';
    else if heightin lt 60 then IBW = (50 - (60- (heightin*2.3)));
    else IBW = (50 + ((heightin-60)*2.3));
  end;
  else put 'Unknown SEX' sex=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 08 Sep 2018 18:17:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculations-in-IF-THEN-statements/m-p/493807#M129995</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-09-08T18:17:38Z</dc:date>
    </item>
    <item>
      <title>Re: Calculations in IF THEN statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculations-in-IF-THEN-statements/m-p/493849#M130017</link>
      <description>&lt;P&gt;I got the following to work without revising the code you provided at all. My guess...you have an issue with the input sex variable - either case sensitivity or length. Try strip(upcase(sex))='F' instead of just sex='F'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
input sex $1. height;
datalines;
M 135
F 145
;
run;

data b;
	set a;
	heightin = height/ 2.54;
	IBW = .;
	if sex = 'F' and heightin lt 60 then IBW = (45 - (60- (heightin*2.3)));
	if sex = 'F' and heightin ge 60 then IBW = (45 + ((heightin-60)*2.3));
	if sex = 'M' and heightin lt 60 then IBW = (50 - (60- (heightin*2.3)));
	if sex = 'M' and heightin ge 60 then IBW = (50 + ((heightin-60)*2.3));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 09 Sep 2018 00:12:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculations-in-IF-THEN-statements/m-p/493849#M130017</guid>
      <dc:creator>bobpep212</dc:creator>
      <dc:date>2018-09-09T00:12:02Z</dc:date>
    </item>
    <item>
      <title>Re: Calculations in IF THEN statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculations-in-IF-THEN-statements/m-p/493900#M130049</link>
      <description>&lt;P&gt;Thanks to all for your ideas. Ultimately it was a case sensitivity issue.&lt;/P&gt;</description>
      <pubDate>Sun, 09 Sep 2018 14:16:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculations-in-IF-THEN-statements/m-p/493900#M130049</guid>
      <dc:creator>NYSAS</dc:creator>
      <dc:date>2018-09-09T14:16:17Z</dc:date>
    </item>
    <item>
      <title>Re: Calculations in IF THEN statements</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculations-in-IF-THEN-statements/m-p/493902#M130050</link>
      <description>Great, thank you! This worked perfectly. (Beginner mistake)&lt;BR /&gt;</description>
      <pubDate>Sun, 09 Sep 2018 14:16:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculations-in-IF-THEN-statements/m-p/493902#M130050</guid>
      <dc:creator>NYSAS</dc:creator>
      <dc:date>2018-09-09T14:16:31Z</dc:date>
    </item>
  </channel>
</rss>

