<?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: How to Calculate distinct count using PROC SQL with missing values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-Calculate-distinct-count-using-PROC-SQL-with-missing/m-p/801421#M315411</link>
    <description>&lt;P&gt;Thanks for your response.&amp;nbsp; your both solutions working for me as of now. Additional question in second solutions:&amp;nbsp; how $hex10. doing the job? By any chance if my character length for 'name' changes to 200 in future, is $hex10. works?&lt;/P&gt;</description>
    <pubDate>Thu, 10 Mar 2022 18:24:25 GMT</pubDate>
    <dc:creator>SASuserlot</dc:creator>
    <dc:date>2022-03-10T18:24:25Z</dc:date>
    <item>
      <title>How to Calculate distinct count using PROC SQL with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Calculate-distinct-count-using-PROC-SQL-with-missing/m-p/801406#M315398</link>
      <description>&lt;P&gt;I tried the following code. I came&amp;nbsp; to know I want not able to find the distinct count if the variable missing in SQL is there a way to circumvent this issue? I have the data with 2 distinct names ( alpha, " ") but when I do distinct count I am only getting one count. Thanks&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data xx;
name= "alpha";
output;
name=" ";
output;
run;

proc sql;
create table xx1 as select   count(distinct name) as cnt from xx ;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 10 Mar 2022 17:46:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Calculate-distinct-count-using-PROC-SQL-with-missing/m-p/801406#M315398</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2022-03-10T17:46:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to Calculate distinct count using PROC SQL with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Calculate-distinct-count-using-PROC-SQL-with-missing/m-p/801411#M315401</link>
      <description>&lt;P&gt;Is this what you are attempting to do?&lt;/P&gt;
&lt;P&gt;Note I changed your xx dataset, as I suspect you want a count of the distinct values&amp;nbsp; ie Alpha count = 5 _blank_ count = 3 in my example&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;data xx;
	do i=1 to 5 ;
		name= "alpha";
		output;
	end ;
	do i=1 to 3 ;
		name=" ";
		output;
	end ;
run;

proc sql;
	create table xx1 as 
	select distinct name, count(*)
	from xx 
	group by name ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If this isn't want you are looking for can you provide an example with a have and want dataset (ie what you have, and what you want after processing)&lt;BR /&gt;Also provide more detailed explanation of what you are attempting to do&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Mar 2022 18:08:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Calculate-distinct-count-using-PROC-SQL-with-missing/m-p/801411#M315401</guid>
      <dc:creator>AMSAS</dc:creator>
      <dc:date>2022-03-10T18:08:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to Calculate distinct count using PROC SQL with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Calculate-distinct-count-using-PROC-SQL-with-missing/m-p/801412#M315402</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/350312"&gt;@SASuserlot&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could add 1 for missing values:&lt;/P&gt;
&lt;PRE&gt;select count(distinct name)&lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;+max(name=" ")&lt;/STRONG&gt;&lt;/FONT&gt; as cnt&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or count distinct hexadecimal representations in your character variable of length 5:&lt;/P&gt;
&lt;PRE&gt;select count(distinct &lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;put(&lt;/STRONG&gt;&lt;/FONT&gt;name&lt;STRONG&gt;&lt;FONT color="#3366FF"&gt;,$hex10.)&lt;/FONT&gt;&lt;/STRONG&gt;) as cnt&lt;/PRE&gt;</description>
      <pubDate>Thu, 10 Mar 2022 18:14:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Calculate-distinct-count-using-PROC-SQL-with-missing/m-p/801412#M315402</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2022-03-10T18:14:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to Calculate distinct count using PROC SQL with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Calculate-distinct-count-using-PROC-SQL-with-missing/m-p/801415#M315405</link>
      <description>&lt;P&gt;PROC FREQ has no problems&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=xx nlevels;
    ods output nlevels=xx1;
    tables name;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 10 Mar 2022 18:18:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Calculate-distinct-count-using-PROC-SQL-with-missing/m-p/801415#M315405</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-03-10T18:18:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to Calculate distinct count using PROC SQL with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Calculate-distinct-count-using-PROC-SQL-with-missing/m-p/801417#M315407</link>
      <description>&lt;P&gt;Thanks for your response. Yes PROC freq don't have any issues. I was looking&amp;nbsp; to explore with&amp;nbsp; SQL. I think&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp; response is working&amp;nbsp; at present.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Mar 2022 18:21:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Calculate-distinct-count-using-PROC-SQL-with-missing/m-p/801417#M315407</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2022-03-10T18:21:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to Calculate distinct count using PROC SQL with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Calculate-distinct-count-using-PROC-SQL-with-missing/m-p/801418#M315408</link>
      <description>&lt;P&gt;Your example is good but not the quite I am looking for . You have&amp;nbsp; two different names&amp;nbsp; (alpha, ' ')out of 10 observations. I was looking for how many different names out of 10 observations not count for 'alpha' or count of missing.&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp; response is working for me as of now&lt;/P&gt;</description>
      <pubDate>Thu, 10 Mar 2022 18:21:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Calculate-distinct-count-using-PROC-SQL-with-missing/m-p/801418#M315408</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2022-03-10T18:21:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to Calculate distinct count using PROC SQL with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Calculate-distinct-count-using-PROC-SQL-with-missing/m-p/801421#M315411</link>
      <description>&lt;P&gt;Thanks for your response.&amp;nbsp; your both solutions working for me as of now. Additional question in second solutions:&amp;nbsp; how $hex10. doing the job? By any chance if my character length for 'name' changes to 200 in future, is $hex10. works?&lt;/P&gt;</description>
      <pubDate>Thu, 10 Mar 2022 18:24:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Calculate-distinct-count-using-PROC-SQL-with-missing/m-p/801421#M315411</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2022-03-10T18:24:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to Calculate distinct count using PROC SQL with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Calculate-distinct-count-using-PROC-SQL-with-missing/m-p/801422#M315412</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/350312"&gt;@SASuserlot&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks for your response. Yes PROC freq don't have any issues. I was looking&amp;nbsp; to explore with&amp;nbsp; SQL. I think&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp; response is working&amp;nbsp; at present.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That's fine. I presented the PROC FREQ answer for people reading along who aren't limiting themselves to PROC SQL. Or for people who prefer straightforward and readable and easily understandable code (as you can see PROC SQL requires a little bit more complicated and less intuitive code).&lt;/P&gt;</description>
      <pubDate>Thu, 10 Mar 2022 18:25:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Calculate-distinct-count-using-PROC-SQL-with-missing/m-p/801422#M315412</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-03-10T18:25:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to Calculate distinct count using PROC SQL with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Calculate-distinct-count-using-PROC-SQL-with-missing/m-p/801426#M315414</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/350312"&gt;@SASuserlot&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Additional question in second solutions:&amp;nbsp; how $hex10. doing the job? By any chance if my character length for 'name' changes to 200 in future, is $hex10. works?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The width &lt;EM&gt;w&lt;/EM&gt; of the $HEX&lt;EM&gt;w&lt;/EM&gt;. format must be greater than or equal to &lt;EM&gt;twice&lt;/EM&gt; the defined length of the character variable to be formatted. So use &lt;FONT face="courier new,courier"&gt;$hex400.&lt;/FONT&gt; for a length-200 variable (Edit: assuming the usual single-byte characters, not Unicode, etc.). The other solution is independent of the length of variable NAME.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Mar 2022 18:35:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Calculate-distinct-count-using-PROC-SQL-with-missing/m-p/801426#M315414</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2022-03-10T18:35:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to Calculate distinct count using PROC SQL with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Calculate-distinct-count-using-PROC-SQL-with-missing/m-p/801427#M315415</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp; thank you, I really appreciate that. Just wanted let you&amp;nbsp; I communicated correctly. I really appreciate your quick responses to my questions all the time.&lt;span class="lia-unicode-emoji" title=":grinning_face:"&gt;😀&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Mar 2022 18:29:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Calculate-distinct-count-using-PROC-SQL-with-missing/m-p/801427#M315415</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2022-03-10T18:29:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to Calculate distinct count using PROC SQL with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Calculate-distinct-count-using-PROC-SQL-with-missing/m-p/801432#M315418</link>
      <description>&lt;P&gt;Thank you. How about if variable is numeric type?&lt;/P&gt;</description>
      <pubDate>Thu, 10 Mar 2022 18:40:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Calculate-distinct-count-using-PROC-SQL-with-missing/m-p/801432#M315418</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2022-03-10T18:40:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to Calculate distinct count using PROC SQL with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Calculate-distinct-count-using-PROC-SQL-with-missing/m-p/801466#M315421</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/350312"&gt;@SASuserlot&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;How about if variable is numeric type?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You might need to know what values you can expect in the numeric variable: Are there &lt;EM&gt;special&lt;/EM&gt; missing values (like .A, .B, ..., ._) and would you like to count these as distinct? Are there floating point values which may contain tiny rounding errors? In this case would you like to count, say, 3 and 3.00000000000001 as different numbers?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If no special missing values are involved (only the usual numeric missing value &lt;FONT face="courier new,courier"&gt;.&lt;/FONT&gt;), you can use&lt;/P&gt;
&lt;PRE&gt;select count(distinct numvar)+max(numvar=.)&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To include distinct special missing values in the count, use&lt;/P&gt;
&lt;PRE&gt;select count(distinct put(numvar,hex16.))&lt;/PRE&gt;
&lt;P&gt;(This time the width of the format is always 16.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Both of the above solutions would distinguish between&amp;nbsp;3 and 3.00000000000001, etc. If you don't want this, use the ROUND function or apply a format that suits your precision goal.&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;select count(distinct put(numvar,best12.))&lt;/PRE&gt;
&lt;P&gt;This would also include distinct special missing values, if any.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Mar 2022 19:12:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Calculate-distinct-count-using-PROC-SQL-with-missing/m-p/801466#M315421</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2022-03-10T19:12:35Z</dc:date>
    </item>
  </channel>
</rss>

