<?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 logic with count and error=1 question in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/IF-Then-logic-with-count-and-error-1-question/m-p/730548#M227488</link>
    <description>Thanks!!!!</description>
    <pubDate>Wed, 31 Mar 2021 23:46:17 GMT</pubDate>
    <dc:creator>mava</dc:creator>
    <dc:date>2021-03-31T23:46:17Z</dc:date>
    <item>
      <title>IF-Then logic with count and error=1 question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-Then-logic-with-count-and-error-1-question/m-p/730510#M227470</link>
      <description>&lt;P&gt;Hi. I am studying for the base certification exam from the 5th edition of the Base Cert Prep book.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a question about these examples that are in the book and I do not understand that the&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. count+1 is counting&lt;/P&gt;&lt;P&gt;2. why an error=1 is in the statement&amp;nbsp;&lt;/P&gt;&lt;P&gt;I understand the conditions, though - just not those 2 statements.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here are the codes for the 2 examples in which I am confused.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I highlighted what I do not understand in blue.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;Example 1:&lt;/U&gt;&lt;/P&gt;&lt;P&gt;if status='OK' and type=3&lt;/P&gt;&lt;P&gt;&amp;nbsp; then &lt;FONT color="#0000FF"&gt;count+1;&amp;nbsp; &amp;nbsp;&lt;FONT color="#993300"&gt; &amp;nbsp;(Does this count the number of type with the value 3? )&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;if (age ne agecheck or time ne3) and &lt;FONT color="#0000FF"&gt;error=1&lt;/FONT&gt; then Test=1;&amp;nbsp; &lt;FONT color="#993300"&gt;(why is error=1 in there? I thought that was if there was at least one error in the program.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000FF"&gt;Question: What does the example 1 program?&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example 2:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if (age ne agecheck or time ne 3)&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;and &lt;FONT color="#0000FF"&gt;error=1&lt;/FONT&gt; then Test=1;&amp;nbsp; &lt;FONT color="#993300"&gt;&amp;nbsp;( I don't understand why the error=1 is in there)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;if status='S' or cond='E'&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;then &lt;FONT color="#0000FF"&gt;Control='Stop'&lt;/FONT&gt;;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;FONT color="#993300"&gt;(I don't understand this one at all or am confused)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000FF"&gt;What does the example 2 program? What is it doing? &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000FF"&gt;Thank you!&amp;nbsp; &amp;nbsp;Mava&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Mar 2021 20:51:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-Then-logic-with-count-and-error-1-question/m-p/730510#M227470</guid>
      <dc:creator>mava</dc:creator>
      <dc:date>2021-03-31T20:51:21Z</dc:date>
    </item>
    <item>
      <title>Re: IF-Then logic with count and error=1 question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-Then-logic-with-count-and-error-1-question/m-p/730514#M227472</link>
      <description>COUNT+1 increments the count variable by 1. It's documented under the SUM statement.&lt;BR /&gt;&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=lestmtsref&amp;amp;docsetTarget=n1dfiqj146yi2cn1maeju9wo7ijs.htm&amp;amp;locale=en" target="_blank"&gt;https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=lestmtsref&amp;amp;docsetTarget=n1dfiqj146yi2cn1maeju9wo7ijs.htm&amp;amp;locale=en&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Regarding your second question, I think you're mixing up the _error_ variable which is an automatic SAS variable. error in this case is a variable in the data set and the logic depends on context and needs.</description>
      <pubDate>Wed, 31 Mar 2021 20:56:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-Then-logic-with-count-and-error-1-question/m-p/730514#M227472</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-03-31T20:56:20Z</dc:date>
    </item>
    <item>
      <title>Re: IF-Then logic with count and error=1 question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-Then-logic-with-count-and-error-1-question/m-p/730521#M227474</link>
      <description>&lt;P&gt;Both of these are just snippets of code. Not a full program. Or even a full data step.&lt;/P&gt;
&lt;P&gt;What the meaning of the statements is depends on the context they are used in.&amp;nbsp; Including the data step they are running in.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In SAS the = is used for equality testing in boolean expressions (type=3) and in assignment statements (CONTROL='Stop'). The SAS compiler knows which you mean by the larger context of how you used them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your code snippets have three types of statements being used.&lt;/P&gt;
&lt;P&gt;IF/THEN statement-&amp;gt;&amp;nbsp; IF condition THEN statement ;&lt;/P&gt;
&lt;P&gt;Assignment statement-&amp;gt;&amp;nbsp; variable = expression;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sum statement-&amp;gt; variable + expression ;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First question:&lt;/P&gt;
&lt;P&gt;The IF/THEN statement means the value of COUNT is incremented by 1 when the condition tested is true.&amp;nbsp; So not just when TYPE=3 but also it is chekcing if STATUS='OK'. The fact that you used a SUM statement means that the variable COUNT will be retained across iterations of the data step instead of being reset to missing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second/Third question:&lt;/P&gt;
&lt;P&gt;In this context ERROR is the name of variable, just like TYPE and STATUS and COUNT in the previous statement.&amp;nbsp; So the meaning of the test ERROR=1 depends on what it means for that variable to have that value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Last question:&lt;/P&gt;
&lt;P&gt;This statement is testing the values of the variable STATUS and COND and then conditionally changing the value of CONTROL to 'Stop'.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Mar 2021 21:22:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-Then-logic-with-count-and-error-1-question/m-p/730521#M227474</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-03-31T21:22:40Z</dc:date>
    </item>
    <item>
      <title>Re: IF-Then logic with count and error=1 question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-Then-logic-with-count-and-error-1-question/m-p/730546#M227486</link>
      <description>Thank u</description>
      <pubDate>Wed, 31 Mar 2021 23:43:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-Then-logic-with-count-and-error-1-question/m-p/730546#M227486</guid>
      <dc:creator>mava</dc:creator>
      <dc:date>2021-03-31T23:43:01Z</dc:date>
    </item>
    <item>
      <title>Re: IF-Then logic with count and error=1 question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-Then-logic-with-count-and-error-1-question/m-p/730547#M227487</link>
      <description>Thank u so much!</description>
      <pubDate>Wed, 31 Mar 2021 23:44:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-Then-logic-with-count-and-error-1-question/m-p/730547#M227487</guid>
      <dc:creator>mava</dc:creator>
      <dc:date>2021-03-31T23:44:24Z</dc:date>
    </item>
    <item>
      <title>Re: IF-Then logic with count and error=1 question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-Then-logic-with-count-and-error-1-question/m-p/730548#M227488</link>
      <description>Thanks!!!!</description>
      <pubDate>Wed, 31 Mar 2021 23:46:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-Then-logic-with-count-and-error-1-question/m-p/730548#M227488</guid>
      <dc:creator>mava</dc:creator>
      <dc:date>2021-03-31T23:46:17Z</dc:date>
    </item>
  </channel>
</rss>

