title: SAS WHERE statement with several conditions
body: <p>In SAS PROC FREQ, using a WHERE statement with multiple conditions, I would like to understand why adding a condition causes a frequency to increase.</p>
  
  <p>The first instance:         </p>
  
  <pre><code>PROC FREQ;
  WHERE X=1 AND Y=1;
  TABLE YEARS;
  RUN;
  </code></pre>
  
  <p>Outputs N=100 for a particular year.   </p>
  
  <p>But: </p>
  
  <pre><code>PROC FREQ;
  WHERE (X=1 AND Y=1) AND A=2 OR B=2;
  TABLE YEARS;
  RUN;
  </code></pre>
  
  <p>Outputs larger N than the previous WHERE for the same year, e.g., N=200.</p>
  
  <p>In the second FREQ and WHERE statement I think the condition in parentheses should be evaluated first, before the AND...OR, and should select the same N=100 as the first WHERE statement. And then the remaining criteria in the line, AND A=2 OR B=2, should select a subset of N=100 have either A=2 or B=2. And consequently, selected N should be less than or equal to 100, but not greater than 100. </p>
  
  <p>This is what I want--the subset of (X=1 AND Y=1)
  that also has either A=2 OR B=2--but it does not seem to be what I am getting. Suggestions?</p>
  
  <p>Is this the correct statement for what I want?</p>
  
  <p><code>WHERE (X=1 AND Y=1 AND A=2) OR (X=1 AND Y=1 AND B=2);</code></p>
  
  <p>Thank you.</p>