title: SQLselect count with case/when
body: <p>I have the following table:</p>
  
  <pre><code>Id  Type 
  1   A
  2   B
  3   C
  4   A
  </code></pre>
  
  <p>I would like to create new table that counts the number of rows which each type has. It is easy to create each table for each type counting, but I would like to make it better in looks and also the performance, so is it possible to do this in one query? I have come up with a query like below but it does not work. The error said that "Result of WHEN clause 2 is not the same data type as the preceding result". 
  Help is appreciated and thanks in advance. </p>
  
  <pre><code>PROC SQL;
     CREATE TABLE WORK.Statistics_Count AS
     SELECT 
        COUNT(Id) as total,
        COUNT(CASE WHEN Type = "A" then Id else . end) as typeA,
        COUNT(CASE WHEN Type = "B" then Id else . end) as typeB,
        COUNT(CASE WHEN Type = "C" then Id else . end) as typeC,
        COUNT(CASE WHEN Type &lt;&gt; "A" then Id else . end) as nonTypeA
     FROM WORK.ListTable;
  QUIT; 
  </code></pre>