title: Group by in Subquery SAS
body: <p>Hi I have a dataset look like this</p>
  
  <pre><code>Brand   Category
  ----------------------
  A       1
  A       1
  A       1
  B       1
  B       1
  C       1
  A       2
  C       2
  C       2
  C       2
  </code></pre>
  
  <p>and I want to get the market share for each brand in each category. Say, market share for A in category 1 is 3/6=50%.</p>
  
  <p>I used the sql code</p>
  
  <pre><code>    proc sql;
      select
      Brand, 
      count(brand) / (select count(category) from dataset group by category) as percent
      from dataset
      group by brand, category;
  </code></pre>
  
  <p>but the SAS report the error of </p>
  
  <pre><code> ERROR: Subquery evaluated to more than one row.
  </code></pre>
  
  <p>Please help. Thank you so much!</p>