<?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 else if statement not working in SAS Studio</title>
    <link>https://communities.sas.com/t5/SAS-Studio/If-then-else-if-statement-not-working/m-p/341681#M2135</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/130450"&gt;@LMP&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I just realized that my if then, else if statement didn't work. I know because all bllresult is equal to zero and there should be some bllresults equal to one. I had no errors or warnings in the log regarding this. I found out when I was doing proc statements using this variable that the variable was not created correctly. Please see the code below. Does anyone have any segestions? I would appreciate any sugestions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;LMP&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;libname mydata "/folders/myshortcuts/myfolder";

run;


Data mydata.temp;

set mydata.bllcinckids2014;

 
/* if result# is greater than or equal to 5 then BLLresult is 1 , if less than 5 then the BLLresult is equal to 0 */

If result &amp;gt;= 5 then bllresult=1; else if result &amp;lt;5 then bllresult=0;
 run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What specifically makes you think "that the variable was not created correctly"?&lt;/P&gt;
&lt;P&gt;If it is because you are getting 0 when result is actually missing that is the correct behavior for SAS: Missing is smaller than anything.&lt;/P&gt;
&lt;P&gt;Or are getting an error? Show the error&lt;/P&gt;
&lt;P&gt;Some value other than 0 or 1&amp;nbsp;(including&amp;nbsp;missing)? Show the entire code for the data step AND the input data. You may have changed the value of result or bllresult prior to or after this step.&lt;/P&gt;
&lt;P&gt;Note that example data should be in the form of a data step so we don't have to guess about characteristics of the variable. Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;</description>
    <pubDate>Thu, 16 Mar 2017 17:08:44 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2017-03-16T17:08:44Z</dc:date>
    <item>
      <title>If then else if statement not working</title>
      <link>https://communities.sas.com/t5/SAS-Studio/If-then-else-if-statement-not-working/m-p/341621#M2126</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just realized that my if then, else if statement didn't work. I know because all bllresult is equal to zero and there should be some bllresults equal to one. I had no errors or warnings in the log regarding this. I found out when I was doing proc statements using this variable that the variable was not created correctly. Please see the code below. Does anyone have any segestions? I would appreciate any sugestions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;LMP&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;libname mydata "/folders/myshortcuts/myfolder";

run;


Data mydata.temp;

set mydata.bllcinckids2014;

 
/* if result# is greater than or equal to 5 then BLLresult is 1 , if less than 5 then the BLLresult is equal to 0 */

If result &amp;gt;= 5 then bllresult=1; else if result &amp;lt;5 then bllresult=0;
 run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2017 15:23:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/If-then-else-if-statement-not-working/m-p/341621#M2126</guid>
      <dc:creator>LMP</dc:creator>
      <dc:date>2017-03-16T15:23:19Z</dc:date>
    </item>
    <item>
      <title>Re: If then else if statement not working</title>
      <link>https://communities.sas.com/t5/SAS-Studio/If-then-else-if-statement-not-working/m-p/341629#M2127</link>
      <description>&lt;P&gt;I don't see any error in your code.&lt;/P&gt;
&lt;P&gt;As a value can be either Greater-Equal or Less-Than you can try next code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data mydata.temp;
   set mydata.bllcinckids2014;
       If result GE 5 then bllresult=1; 
                      else bllresult=0;
 run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 16 Mar 2017 15:39:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/If-then-else-if-statement-not-working/m-p/341629#M2127</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-03-16T15:39:46Z</dc:date>
    </item>
    <item>
      <title>Re: If then else if statement not working</title>
      <link>https://communities.sas.com/t5/SAS-Studio/If-then-else-if-statement-not-working/m-p/341632#M2128</link>
      <description>&lt;P&gt;Run this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select max(result) from mydata.bllcinckids2014;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also make sure that result is a numeric variable.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2017 15:40:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/If-then-else-if-statement-not-working/m-p/341632#M2128</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-03-16T15:40:26Z</dc:date>
    </item>
    <item>
      <title>Re: If then else if statement not working</title>
      <link>https://communities.sas.com/t5/SAS-Studio/If-then-else-if-statement-not-working/m-p/341648#M2129</link>
      <description>&lt;P&gt;Show some test data in the form of a datastep. &amp;nbsp;Could your resulvariable be character, if so your logic will not work. &amp;nbsp;Also note, for binary choices ifn/ifc functions are simpler:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  bllresult=ifn(result &amp;gt;= 5,1,0);
run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 16 Mar 2017 16:02:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/If-then-else-if-statement-not-working/m-p/341648#M2129</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-03-16T16:02:48Z</dc:date>
    </item>
    <item>
      <title>Re: If then else if statement not working</title>
      <link>https://communities.sas.com/t5/SAS-Studio/If-then-else-if-statement-not-working/m-p/341681#M2135</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/130450"&gt;@LMP&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I just realized that my if then, else if statement didn't work. I know because all bllresult is equal to zero and there should be some bllresults equal to one. I had no errors or warnings in the log regarding this. I found out when I was doing proc statements using this variable that the variable was not created correctly. Please see the code below. Does anyone have any segestions? I would appreciate any sugestions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;LMP&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;libname mydata "/folders/myshortcuts/myfolder";

run;


Data mydata.temp;

set mydata.bllcinckids2014;

 
/* if result# is greater than or equal to 5 then BLLresult is 1 , if less than 5 then the BLLresult is equal to 0 */

If result &amp;gt;= 5 then bllresult=1; else if result &amp;lt;5 then bllresult=0;
 run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What specifically makes you think "that the variable was not created correctly"?&lt;/P&gt;
&lt;P&gt;If it is because you are getting 0 when result is actually missing that is the correct behavior for SAS: Missing is smaller than anything.&lt;/P&gt;
&lt;P&gt;Or are getting an error? Show the error&lt;/P&gt;
&lt;P&gt;Some value other than 0 or 1&amp;nbsp;(including&amp;nbsp;missing)? Show the entire code for the data step AND the input data. You may have changed the value of result or bllresult prior to or after this step.&lt;/P&gt;
&lt;P&gt;Note that example data should be in the form of a data step so we don't have to guess about characteristics of the variable. Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2017 17:08:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/If-then-else-if-statement-not-working/m-p/341681#M2135</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-03-16T17:08:44Z</dc:date>
    </item>
    <item>
      <title>Re: If then else if statement not working</title>
      <link>https://communities.sas.com/t5/SAS-Studio/If-then-else-if-statement-not-working/m-p/341683#M2136</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There was no error. And there arent any missing results. The reason I know the if then else statement wasn't working is because if I look at the result section there are values greater than 5 and ther bllresult is still labeled as zero.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kindly,&lt;/P&gt;&lt;P&gt;LMP&lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2017 17:21:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/If-then-else-if-statement-not-working/m-p/341683#M2136</guid>
      <dc:creator>LMP</dc:creator>
      <dc:date>2017-03-16T17:21:39Z</dc:date>
    </item>
    <item>
      <title>Re: If then else if statement not working</title>
      <link>https://communities.sas.com/t5/SAS-Studio/If-then-else-if-statement-not-working/m-p/341687#M2138</link>
      <description>&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2017 17:31:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/If-then-else-if-statement-not-working/m-p/341687#M2138</guid>
      <dc:creator>LMP</dc:creator>
      <dc:date>2017-03-16T17:31:37Z</dc:date>
    </item>
    <item>
      <title>Re: If then else if statement not working</title>
      <link>https://communities.sas.com/t5/SAS-Studio/If-then-else-if-statement-not-working/m-p/341723#M2140</link>
      <description>&lt;P&gt;If it was because the variable was of type character, a look into the log would have alerted you about the automatic conversion.&lt;/P&gt;
&lt;P&gt;Such notes are always a bad sign.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2017 18:54:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/If-then-else-if-statement-not-working/m-p/341723#M2140</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-03-16T18:54:23Z</dc:date>
    </item>
  </channel>
</rss>

