<?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: Problem with If-Then Statement in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Problem-with-If-Then-Statement/m-p/383725#M65614</link>
    <description>&lt;P&gt;You can simplfy it:&lt;/P&gt;
&lt;PRE&gt;ssb=ifn(sum(eat_fruit_juice_m_r,eat_100juice_m_r,...) &amp;gt; 0,0,1);&lt;/PRE&gt;
&lt;P&gt;First this sums() all your variables (I have only put in the first couple), as sum of 0,0,0 etc is 0. &amp;nbsp;Then it uses the binary result ifn() function rather than if then else, just a bit shorted in these yes/no cases, so return 0 if condition true, 1 otherwise.&lt;/P&gt;</description>
    <pubDate>Fri, 28 Jul 2017 14:48:21 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2017-07-28T14:48:21Z</dc:date>
    <item>
      <title>Problem with If-Then Statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Problem-with-If-Then-Statement/m-p/383720#M65612</link>
      <description>&lt;P&gt;Using SAS Version 9.3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to create a variable name SSB which if all of the variables (each of them are binary are 0 and 1) =0 (therefore using AND) then it should be =0 and if any of the variables have =1 then that would =1 (therefore using OR) &amp;nbsp;See code below. This is not working however but I don't want the 0's to be OR's since that is not what I want to capture....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;if eat_fruitjuice_m_r =0 AND&lt;BR /&gt;eat_100juice_m_r =0 AND&lt;BR /&gt;eat_juicedrink_m_r =0 AND&lt;BR /&gt;eat_soda_m_r =0 AND&lt;BR /&gt;eat_ssb_m_r =0 AND&lt;BR /&gt;eat_sugarwater_m_r=0 AND&lt;BR /&gt;eat_tea_m_r =0 AND&lt;BR /&gt;eat_vegjuice_m_r=0 then SSB=0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;else if eat_fruitjuice_m_r ne . and eat_fruitjuice_m_r=1 OR&lt;BR /&gt;eat_100juice_m_r ne . and eat_100juice_m_r=1 OR&lt;BR /&gt;eat_juicedrink_m_r ne . and eat_juicedrink_m_r =1 OR&lt;BR /&gt;eat_soda_m_r ne . and eat_soda_m =1 OR&lt;BR /&gt;eat_ssb_m_r ne . and eat_ssb_m_r=1 OR&lt;BR /&gt;eat_sugarwater_m_r ne . and eat_sugarwater_m_r=1 OR&lt;BR /&gt;eat_tea_m_r ne . and eat_tea_m_r =1 OR&lt;BR /&gt;eat_vegjuice_m_r ne . and eat_vegjuice_m_r=1 then SSB=1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Suggestions?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jul 2017 14:40:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Problem-with-If-Then-Statement/m-p/383720#M65612</guid>
      <dc:creator>Sas20</dc:creator>
      <dc:date>2017-07-28T14:40:46Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with If-Then Statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Problem-with-If-Then-Statement/m-p/383725#M65614</link>
      <description>&lt;P&gt;You can simplfy it:&lt;/P&gt;
&lt;PRE&gt;ssb=ifn(sum(eat_fruit_juice_m_r,eat_100juice_m_r,...) &amp;gt; 0,0,1);&lt;/PRE&gt;
&lt;P&gt;First this sums() all your variables (I have only put in the first couple), as sum of 0,0,0 etc is 0. &amp;nbsp;Then it uses the binary result ifn() function rather than if then else, just a bit shorted in these yes/no cases, so return 0 if condition true, 1 otherwise.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jul 2017 14:48:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Problem-with-If-Then-Statement/m-p/383725#M65614</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-07-28T14:48:21Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with If-Then Statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Problem-with-If-Then-Statement/m-p/383740#M65615</link>
      <description>&lt;P&gt;Some example data is always helpful such as a few inputs and what you are getting for output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"Doesn't work" is awful vague.&lt;BR /&gt;&lt;BR /&gt;Are there errors in the log?: Post the code and log in a code box opened with the {i} to maintain formatting of error messages.&lt;BR /&gt;&lt;BR /&gt;No output? Post any log in a code box.&lt;BR /&gt;&lt;BR /&gt;Unexpected output? Provide input data in the form of a dataset, the actual results and the expected results. Data should be in the form of a data step. Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suspect that your issue may be in the code like this&lt;/P&gt;
&lt;PRE&gt;if eat_fruitjuice_m_r ne . and eat_fruitjuice_m_r=1 OR&lt;/PRE&gt;
&lt;P&gt;where you may intend:&lt;/P&gt;
&lt;PRE&gt;if ( eat_fruitjuice_m_r ne . and eat_fruitjuice_m_r=1 ) OR&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There may be some solutions with other functions but without explicit examples of the values the suggestions may not "work" for all cases.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also is your intent to have SSB equal to 1 or 0 for all records or is there some where it would be missing such as one of your eat variables missing?&lt;/P&gt;</description>
      <pubDate>Fri, 28 Jul 2017 15:04:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Problem-with-If-Then-Statement/m-p/383740#M65615</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-07-28T15:04:06Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with If-Then Statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Problem-with-If-Then-Statement/m-p/383972#M65622</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/156255"&gt;@Sas20&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;Something like below should work. Just list in the array statement all the flag variables you want to use for your test.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  eat_fruitjuice_m_r =1;
  eat_100juice_m_r =1;
  eat_juicedrink_m_r =1;
  eat_soda_m_r =1;
  eat_ssb_m_r =1;
  eat_sugarwater_m_r=1;
  eat_tea_m_r =1;
  eat_vegjuice_m_r=1;
  output;
  eat_soda_m_r =0;
  output;
  eat_soda_m_r =.;
  output;
run;

data want;
  set have;
  array eat_vars {*} eat_:;
  SSB= &amp;nbsp;( sum(of eat_vars[*])=dim(eat_vars) );
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 29 Jul 2017 04:44:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Problem-with-If-Then-Statement/m-p/383972#M65622</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-07-29T04:44:21Z</dc:date>
    </item>
  </channel>
</rss>

