<?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: SAS sql not counting null values as expected. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-sql-not-counting-null-values-as-expected/m-p/459669#M116776</link>
    <description>&lt;P&gt;I believe that when you put a number in like that it noramlly reflects the logical position of the variable in the dataset, so:&lt;/P&gt;
&lt;PRE&gt;group by 1,3,4;&lt;/PRE&gt;
&lt;P&gt;Groups by variable which is found in position 1 of the data, and then by position 3 variable, then by position 4 variable.&amp;nbsp; I would avoid such notation as a change to the data can drastically alter code output.&lt;/P&gt;</description>
    <pubDate>Thu, 03 May 2018 14:13:33 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2018-05-03T14:13:33Z</dc:date>
    <item>
      <title>SAS sql not counting null values as expected.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-sql-not-counting-null-values-as-expected/m-p/459614#M116760</link>
      <description>&lt;P&gt;Hi all,&lt;BR /&gt;&lt;BR /&gt;I have a dataset which has a variable that by default is null, but is changed to one of 6 or 7 category names&amp;nbsp;should an incident occur.&lt;BR /&gt;I want to count the number of records in each category, including the default null category. Here's my code.&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table no_in_cats as&lt;/P&gt;&lt;P&gt;select&lt;/P&gt;&lt;P&gt;var1,&lt;/P&gt;&lt;P&gt;count(var1) as no_in_cat&lt;/P&gt;&lt;P&gt;from dataset&lt;/P&gt;&lt;P&gt;group by var1;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I get output like this:&lt;BR /&gt;var1&amp;nbsp;&amp;nbsp; &amp;nbsp;no_in_cat&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&lt;BR /&gt;A&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 65&lt;BR /&gt;B &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 46596&lt;BR /&gt;C &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3229&lt;BR /&gt;D &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 26&lt;BR /&gt;E &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 104&lt;BR /&gt;F &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 102317&lt;/P&gt;&lt;P&gt;I know that the number of nulls should be the largest number by far, so these results are concerning!&lt;BR /&gt;Any idea about where I'm going wrong?&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 03 May 2018 11:35:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-sql-not-counting-null-values-as-expected/m-p/459614#M116760</guid>
      <dc:creator>Sean100</dc:creator>
      <dc:date>2018-05-03T11:35:22Z</dc:date>
    </item>
    <item>
      <title>Re: SAS sql not counting null values as expected.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-sql-not-counting-null-values-as-expected/m-p/459628#M116768</link>
      <description>&lt;P&gt;Its hard to say, can't see any data.&amp;nbsp; Your sql:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table no_in_cats as
  select var1,count(*) as no_in_cat
  from dataset
  group by var1;
quit;&lt;/PRE&gt;
&lt;P&gt;Seems fine (though wouldn't call a dataset "dataset").&amp;nbsp; Perhaps post some test data in the form of a datastep so we have something to see.&lt;/P&gt;</description>
      <pubDate>Thu, 03 May 2018 12:29:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-sql-not-counting-null-values-as-expected/m-p/459628#M116768</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-05-03T12:29:42Z</dc:date>
    </item>
    <item>
      <title>Re: SAS sql not counting null values as expected.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-sql-not-counting-null-values-as-expected/m-p/459647#M116771</link>
      <description>Hi,&lt;BR /&gt;The * you have in your count function is not in my code, I changed that and as a result my code works! Why is this?&lt;BR /&gt;Thanks.&lt;BR /&gt;&lt;BR /&gt;P.S. I agree with your point about datasets, I changed the names in my code for the post &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Thu, 03 May 2018 13:27:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-sql-not-counting-null-values-as-expected/m-p/459647#M116771</guid>
      <dc:creator>Sean100</dc:creator>
      <dc:date>2018-05-03T13:27:35Z</dc:date>
    </item>
    <item>
      <title>Re: SAS sql not counting null values as expected.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-sql-not-counting-null-values-as-expected/m-p/459653#M116773</link>
      <description>&lt;P&gt;Well, I believe it is because nulls are not counted:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.techonthenet.com/sql/count.php" target="_blank"&gt;https://www.techonthenet.com/sql/count.php&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I always tend to use * - or check all variables - to do a count of rows in case blanks are present.&lt;/P&gt;</description>
      <pubDate>Thu, 03 May 2018 13:38:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-sql-not-counting-null-values-as-expected/m-p/459653#M116773</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-05-03T13:38:08Z</dc:date>
    </item>
    <item>
      <title>Re: SAS sql not counting null values as expected.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-sql-not-counting-null-values-as-expected/m-p/459663#M116774</link>
      <description>&lt;P&gt;COUNT(varname) will count the number of non-missing values for a variable. To just count observations use COUNT(*).&amp;nbsp; I have seen some people put a constant there instead of the *.&amp;nbsp; So COUNT(1).&amp;nbsp; Although COUNT(5) would work just the same as COUNT(1).&lt;/P&gt;</description>
      <pubDate>Thu, 03 May 2018 14:05:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-sql-not-counting-null-values-as-expected/m-p/459663#M116774</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-05-03T14:05:37Z</dc:date>
    </item>
    <item>
      <title>Re: SAS sql not counting null values as expected.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-sql-not-counting-null-values-as-expected/m-p/459669#M116776</link>
      <description>&lt;P&gt;I believe that when you put a number in like that it noramlly reflects the logical position of the variable in the dataset, so:&lt;/P&gt;
&lt;PRE&gt;group by 1,3,4;&lt;/PRE&gt;
&lt;P&gt;Groups by variable which is found in position 1 of the data, and then by position 3 variable, then by position 4 variable.&amp;nbsp; I would avoid such notation as a change to the data can drastically alter code output.&lt;/P&gt;</description>
      <pubDate>Thu, 03 May 2018 14:13:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-sql-not-counting-null-values-as-expected/m-p/459669#M116776</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-05-03T14:13:33Z</dc:date>
    </item>
    <item>
      <title>Re: SAS sql not counting null values as expected.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-sql-not-counting-null-values-as-expected/m-p/459674#M116781</link>
      <description>&lt;P&gt;You can use position numbers in GROUP BY or ORDER BY clauses. Not in aggregate function calls.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Test code&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
 set sashelp.class ;
 if _n_ in (1,3) then call missing(age);
 if _n_ in (2,3,4) then call missing(height);
run;

proc sql;
 select
  count(*) as count_star
, count(1) as count_1
, count(1000) as count_1000
, count(.) as count_missing
, count(' ') as count_blank
, count(name) as count_name
, count(age) as count_age
, count(height) as count_height
from test
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 03 May 2018 14:27:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-sql-not-counting-null-values-as-expected/m-p/459674#M116781</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-05-03T14:27:48Z</dc:date>
    </item>
  </channel>
</rss>

