<?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: proc sql count in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-count/m-p/289519#M59802</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/40773"&gt;@Bal23&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Thanks. But the example you list, the ID is not missing&lt;/P&gt;
&lt;P&gt;for me, as long as ID is not missing, I do need to count&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If an ID only has missing values in var, it would always count as 0.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You might consider to rephrase your requirement and provide "have" and "want" data as examples.&lt;/P&gt;</description>
    <pubDate>Thu, 04 Aug 2016 13:25:07 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2016-08-04T13:25:07Z</dc:date>
    <item>
      <title>proc sql count</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-count/m-p/289502#M59796</link>
      <description>&lt;P&gt;when I use proc sql;&amp;nbsp; count (var) as&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;it might have duplicate records for a single ID&lt;/P&gt;
&lt;P&gt;i want to know will they count duplicate records as once, or count more times?&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 04 Aug 2016 12:36:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-count/m-p/289502#M59796</guid>
      <dc:creator>Bal23</dc:creator>
      <dc:date>2016-08-04T12:36:18Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql count</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-count/m-p/289509#M59797</link>
      <description>&lt;P&gt;Have you tried it? &amp;nbsp;There are several possible answers to that depending on the data and the code used. &amp;nbsp;Here is the SAS documentation on aggregate functions:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a002473699.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a002473699.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want unique values within the group in question, then you put distinct&lt;/P&gt;
&lt;P&gt;count(distinct var)...&lt;/P&gt;</description>
      <pubDate>Thu, 04 Aug 2016 12:58:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-count/m-p/289509#M59797</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-08-04T12:58:43Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql count</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-count/m-p/289510#M59798</link>
      <description>&lt;P&gt;I use county (distinct ID), I get smaller numbers&lt;/P&gt;
&lt;P&gt;then I use another way&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=have nodupkey;&lt;/P&gt;
&lt;P&gt;by id date;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;data have2;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;by id date;&lt;/P&gt;
&lt;P&gt;if first.id then index=1; else index=2;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;proc freq data=have2;&lt;/P&gt;
&lt;P&gt;tables cat1*cat2;&lt;/P&gt;
&lt;P&gt;where index=1;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But the numbers I got are smaller than I use count disinct id. can any body tell why? which is correct? Thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Aug 2016 12:59:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-count/m-p/289510#M59798</guid>
      <dc:creator>Bal23</dc:creator>
      <dc:date>2016-08-04T12:59:06Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql count</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-count/m-p/289511#M59799</link>
      <description>&lt;P&gt;count(var) will increment for every non-missing value in the dataset.&lt;/P&gt;
&lt;P&gt;If you want to count a group as one if it has at least one non-missing value, you will have to pre-process the dataset:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id value;
cards;
1 3
1 2
1 .
2 .
2 .
3 5
3 6
3 7
;
run;

proc sort
  data=have (where=(value ne .))
  out=int
  nodupkey
;
by id;
run;

proc print data=int;run;

proc sql;
select count(value)
from int
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Output:&lt;/P&gt;
&lt;PRE&gt;Obs    id    value

 1      1      3  
 2      3      5  
                  

             
     --------
            2

&lt;/PRE&gt;</description>
      <pubDate>Thu, 04 Aug 2016 13:02:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-count/m-p/289511#M59799</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-08-04T13:02:34Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql count</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-count/m-p/289513#M59800</link>
      <description>&lt;P&gt;Thanks. But the example you list, the ID is not missing&lt;/P&gt;
&lt;P&gt;for me, as long as ID is not missing, I do need to count&lt;/P&gt;</description>
      <pubDate>Thu, 04 Aug 2016 13:06:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-count/m-p/289513#M59800</guid>
      <dc:creator>Bal23</dc:creator>
      <dc:date>2016-08-04T13:06:16Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql count</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-count/m-p/289514#M59801</link>
      <description>&lt;P&gt;Do you have missing values? If so, check how the Procs handle them.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Aug 2016 13:09:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-count/m-p/289514#M59801</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-08-04T13:09:34Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql count</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-count/m-p/289519#M59802</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/40773"&gt;@Bal23&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Thanks. But the example you list, the ID is not missing&lt;/P&gt;
&lt;P&gt;for me, as long as ID is not missing, I do need to count&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If an ID only has missing values in var, it would always count as 0.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You might consider to rephrase your requirement and provide "have" and "want" data as examples.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Aug 2016 13:25:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-count/m-p/289519#M59802</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-08-04T13:25:07Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql count</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-sql-count/m-p/289543#M59811</link>
      <description>&lt;P&gt;Just test it&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  do var=1,2,3,4,4,5;
    output;
  end;
  call missing(var);
  output;
run;

proc sql;
  select 
    count(*) as n_all_rows,
    count(var) as n_var_rows,
    count(distinct var) as n_distinct_var_rows
  from have
  ;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/4434i6FB4E8B1C8709BD4/image-size/original?v=v2&amp;amp;px=-1" border="0" alt="Capture.PNG" title="Capture.PNG" /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Aug 2016 14:09:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-sql-count/m-p/289543#M59811</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2016-08-04T14:09:54Z</dc:date>
    </item>
  </channel>
</rss>

