<?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: Identify the true if-substatement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Identify-the-true-if-substatement/m-p/490115#M128135</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/202610"&gt;@Emjay&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Well, of course I could break it down in&amp;nbsp;one if-statenment&amp;nbsp;for every&amp;nbsp;reason but I was hoping for an all-in-one-way...&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Since you couldn't provide a rule in a very concise manner in English that is often a clue that the code will not be brief either. Five variables, a different set for each time interval value, a mix of combinations of values I would find a very unlikely candidate for "all-in-one-way" code whatever that might be.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BTW, you want to be aware that &amp;lt; or &amp;lt;= (or LT and LE) conditions are true when a value is missing. If you do not want the evaluation&lt;/P&gt;</description>
    <pubDate>Mon, 27 Aug 2018 15:16:24 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2018-08-27T15:16:24Z</dc:date>
    <item>
      <title>Identify the true if-substatement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-the-true-if-substatement/m-p/490049#M128104</link>
      <description>&lt;P&gt;Let's say I have the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input time count rate1 rate2 settings;
cards;
0.65 3 1.2 0.5 7
2.25 5 0.7 0.7 2
7 4 0.8 0.8 3
7 4 0.8 0.8 6
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Now I have the following rule for state '&lt;STRONG&gt;99&lt;/STRONG&gt;':&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data almost_want;
set have;
if 
(time&amp;lt;=1 and (
	(count&amp;gt;=1)
))
or
(1&amp;lt;time&amp;lt;=3 and (
	(count&amp;gt;=2 and rate1&amp;gt;0.55 and rate2&amp;gt;0.4)
))
or
(3&amp;lt;time and (
	(settings&amp;lt;=4 and count&amp;gt;=2 and rate1&amp;gt;0.55 and rate2&amp;gt;0.4)
	or
	(settings&amp;gt;=5 and count&amp;gt;=3 and rate1&amp;gt;0.55 and rate2&amp;gt;0.4)
))
then State=99;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But what I actually want is this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
input time count rate1 rate2 settings State reason;
cards;
0.65 3 1.2 0.5 7 99 1
2.25 5 0.7 0.7 2 99 2
7 4 0.8 0.8 3 99 3
7 4 0.8 0.8 6 99 4
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So not only '&lt;STRONG&gt;99&lt;/STRONG&gt;' but also because of which condition it is '&lt;STRONG&gt;99&lt;/STRONG&gt;'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In this example I have only one state cause it's enough to describe my problem but in the 'real' data it's five states with up to seven substatements per state.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to find out which substatement of my if-condition was true?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So something like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data almost_want;
set have;
if 
(time&amp;lt;=1 and (
	(count&amp;gt;=1)
	then reason=1
))
or
(1&amp;lt;time&amp;lt;=3 and (
	(count&amp;gt;=2 and rate1&amp;gt;0.55 and rate2&amp;gt;0.4)
	then reason=2
))
or
(3&amp;lt;time and (
	(settings&amp;lt;=4 and count&amp;gt;=2 and rate1&amp;gt;0.55 and rate2&amp;gt;0.4)
	then reason=3
	or
	(settings&amp;gt;=5 and count&amp;gt;=3 and rate1&amp;gt;0.55 and rate2&amp;gt;0.4)
	then reason=4
))
then State=99;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 27 Aug 2018 12:35:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-the-true-if-substatement/m-p/490049#M128104</guid>
      <dc:creator>Emjay</dc:creator>
      <dc:date>2018-08-27T12:35:09Z</dc:date>
    </item>
    <item>
      <title>Re: Identify the true if-substatement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-the-true-if-substatement/m-p/490052#M128106</link>
      <description>&lt;P&gt;Don't try to do it all in one statement.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if time &amp;lt;= 1 and count=1 then do;
   reason=1;
   state=99;
end;
else if (1 &amp;lt; time &amp;lt;= 3) and (count &amp;gt; 2 and rate1 &amp;gt; 0.55 and rate2 &amp;gt; 0.4) then do;
   reason=2;
   state=99;
end;
else .... similarly for other reasons&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Using a few statements makes it easy.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Aug 2018 12:44:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-the-true-if-substatement/m-p/490052#M128106</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-08-27T12:44:18Z</dc:date>
    </item>
    <item>
      <title>Re: Identify the true if-substatement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-the-true-if-substatement/m-p/490056#M128107</link>
      <description>&lt;P&gt;Well, of course I could break it down in&amp;nbsp;one if-statenment&amp;nbsp;for every&amp;nbsp;reason but I was hoping for an all-in-one-way...&lt;/P&gt;</description>
      <pubDate>Mon, 27 Aug 2018 12:47:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-the-true-if-substatement/m-p/490056#M128107</guid>
      <dc:creator>Emjay</dc:creator>
      <dc:date>2018-08-27T12:47:22Z</dc:date>
    </item>
    <item>
      <title>Re: Identify the true if-substatement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-the-true-if-substatement/m-p/490115#M128135</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/202610"&gt;@Emjay&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Well, of course I could break it down in&amp;nbsp;one if-statenment&amp;nbsp;for every&amp;nbsp;reason but I was hoping for an all-in-one-way...&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Since you couldn't provide a rule in a very concise manner in English that is often a clue that the code will not be brief either. Five variables, a different set for each time interval value, a mix of combinations of values I would find a very unlikely candidate for "all-in-one-way" code whatever that might be.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BTW, you want to be aware that &amp;lt; or &amp;lt;= (or LT and LE) conditions are true when a value is missing. If you do not want the evaluation&lt;/P&gt;</description>
      <pubDate>Mon, 27 Aug 2018 15:16:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-the-true-if-substatement/m-p/490115#M128135</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-08-27T15:16:24Z</dc:date>
    </item>
    <item>
      <title>Re: Identify the true if-substatement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-the-true-if-substatement/m-p/490343#M128267</link>
      <description>&lt;P&gt;Yes, the conditions are a little nested, but that's unfortunately as it is.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With all-in-one I wasn't necessarily hoping for super short code, but maybe for a way to mark the true if-condition without writing a if-statement for every single one. I thought SAS maybe provides such a functionality...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But thanks for the hint with the &amp;lt; and missing values. Luckily I don't have those.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Aug 2018 06:45:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-the-true-if-substatement/m-p/490343#M128267</guid>
      <dc:creator>Emjay</dc:creator>
      <dc:date>2018-08-28T06:45:42Z</dc:date>
    </item>
  </channel>
</rss>

