<?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: To find count and matching in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/To-find-count-and-matching/m-p/556561#M9851</link>
    <description>&lt;P&gt;This little example covers how to count distinct and totals.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*This demonstrates how to count the number of unique occurences of a variable
across groups. It uses the SASHELP.CARS dataset which is available with any SAS installation.
The objective is to determine the number of unique car makers by origin/
Note: The SQL solution can be off if you have a large data set and these are not the only two ways to calculate distinct counts.
If you're dealing with a large data set other methods may be appropriate.*/

*Count distinct IDs;
proc sql;
create table distinct_sql as
select origin, count(distinct make) as n_make
from sashelp.cars
group by origin;
quit;

*Double PROC FREQ;
proc freq data=sashelp.cars noprint;
table origin * make / out=origin_make;
run;

proc freq data=origin_make noprint;
table origin / out= distinct_freq;
run;

title 'PROC FREQ';
proc print data=distinct_freq;
run;
title 'PROC SQL';
proc print data=distinct_sql;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/203162"&gt;@dhruvakumar&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi Friends,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need your help ,in the below situation.&lt;/P&gt;
&lt;P&gt;I have a char type variable as number, I need to find the total count in the variable ,and unique count( with out duplication) and how many numbers are there same.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For instance&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;x is char&lt;/P&gt;
&lt;P&gt;x= 1234567849&lt;/P&gt;
&lt;P&gt;I need to find total count = 10&lt;/P&gt;
&lt;P&gt;unique count = 9 (because 4 repeated twice)&lt;/P&gt;
&lt;P&gt;one number is matching i.e 4&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kindly help on the above.Thanks you very much.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Dhruva&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 06 May 2019 20:19:30 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2019-05-06T20:19:30Z</dc:date>
    <item>
      <title>To find count and matching</title>
      <link>https://communities.sas.com/t5/New-SAS-User/To-find-count-and-matching/m-p/556539#M9844</link>
      <description>&lt;P&gt;Hi Friends,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need your help ,in the below situation.&lt;/P&gt;&lt;P&gt;I have a char type variable as number, I need to find the total count in the variable ,and unique count( with out duplication) and how many numbers are there same.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For instance&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;x is char&lt;/P&gt;&lt;P&gt;x= 1234567849&lt;/P&gt;&lt;P&gt;I need to find total count = 10&lt;/P&gt;&lt;P&gt;unique count = 9 (because 4 repeated twice)&lt;/P&gt;&lt;P&gt;one number is matching i.e 4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kindly help on the above.Thanks you very much.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dhruva&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 May 2019 19:44:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/To-find-count-and-matching/m-p/556539#M9844</guid>
      <dc:creator>dhruvakumar</dc:creator>
      <dc:date>2019-05-06T19:44:50Z</dc:date>
    </item>
    <item>
      <title>Re: To find count and matching</title>
      <link>https://communities.sas.com/t5/New-SAS-User/To-find-count-and-matching/m-p/556542#M9845</link>
      <description>&lt;P&gt;Do you just have the one value or do you need to do this for multiple values?&lt;/P&gt;</description>
      <pubDate>Mon, 06 May 2019 19:47:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/To-find-count-and-matching/m-p/556542#M9845</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-05-06T19:47:21Z</dc:date>
    </item>
    <item>
      <title>Re: To find count and matching</title>
      <link>https://communities.sas.com/t5/New-SAS-User/To-find-count-and-matching/m-p/556547#M9847</link>
      <description>&lt;P&gt;Perhaps something like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
x="1234567849";
run;

data temp(keep=y);
   set have;
   do i=1 to length(x);
      y=char(x, i);
      output;
   end;
run;

proc sql;
   create table want as
   select count(*) as totalcount, 
          count(distinct y) as uniquecount
   from temp;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 06 May 2019 19:57:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/To-find-count-and-matching/m-p/556547#M9847</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-05-06T19:57:35Z</dc:date>
    </item>
    <item>
      <title>Re: To find count and matching</title>
      <link>https://communities.sas.com/t5/New-SAS-User/To-find-count-and-matching/m-p/556561#M9851</link>
      <description>&lt;P&gt;This little example covers how to count distinct and totals.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*This demonstrates how to count the number of unique occurences of a variable
across groups. It uses the SASHELP.CARS dataset which is available with any SAS installation.
The objective is to determine the number of unique car makers by origin/
Note: The SQL solution can be off if you have a large data set and these are not the only two ways to calculate distinct counts.
If you're dealing with a large data set other methods may be appropriate.*/

*Count distinct IDs;
proc sql;
create table distinct_sql as
select origin, count(distinct make) as n_make
from sashelp.cars
group by origin;
quit;

*Double PROC FREQ;
proc freq data=sashelp.cars noprint;
table origin * make / out=origin_make;
run;

proc freq data=origin_make noprint;
table origin / out= distinct_freq;
run;

title 'PROC FREQ';
proc print data=distinct_freq;
run;
title 'PROC SQL';
proc print data=distinct_sql;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/203162"&gt;@dhruvakumar&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi Friends,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need your help ,in the below situation.&lt;/P&gt;
&lt;P&gt;I have a char type variable as number, I need to find the total count in the variable ,and unique count( with out duplication) and how many numbers are there same.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For instance&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;x is char&lt;/P&gt;
&lt;P&gt;x= 1234567849&lt;/P&gt;
&lt;P&gt;I need to find total count = 10&lt;/P&gt;
&lt;P&gt;unique count = 9 (because 4 repeated twice)&lt;/P&gt;
&lt;P&gt;one number is matching i.e 4&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kindly help on the above.Thanks you very much.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Dhruva&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 May 2019 20:19:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/To-find-count-and-matching/m-p/556561#M9851</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-05-06T20:19:30Z</dc:date>
    </item>
    <item>
      <title>Re: To find count and matching</title>
      <link>https://communities.sas.com/t5/New-SAS-User/To-find-count-and-matching/m-p/556612#M9858</link>
      <description>&lt;P&gt;To me, this is simple and direct:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set have;
   array c {0:9} c_0 - c_9;
   do k=1 to length(charvar);
      digit = input(substr(charvar, k, 1), 1.);
      if (0 &amp;lt;= digit &amp;lt;= 9) then c{digit} = sum(c{digit}, 1);
   end;
   total_count = sum(of c{*});
   unique_count = n(of c{*});
   drop k;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 06 May 2019 22:55:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/To-find-count-and-matching/m-p/556612#M9858</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-05-06T22:55:52Z</dc:date>
    </item>
    <item>
      <title>Re: To find count and matching</title>
      <link>https://communities.sas.com/t5/New-SAS-User/To-find-count-and-matching/m-p/556639#M9865</link>
      <description>&lt;P&gt;HI,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanking you.Is there any way to find matching repeated number count, for instance in the above example 4 is repeated twice so counted should be 2.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dhruva&lt;/P&gt;</description>
      <pubDate>Tue, 07 May 2019 02:33:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/To-find-count-and-matching/m-p/556639#M9865</guid>
      <dc:creator>dhruvakumar</dc:creator>
      <dc:date>2019-05-07T02:33:40Z</dc:date>
    </item>
    <item>
      <title>Re: To find count and matching</title>
      <link>https://communities.sas.com/t5/New-SAS-User/To-find-count-and-matching/m-p/556640#M9866</link>
      <description>&lt;P&gt;It's already in there.&amp;nbsp; Try printing the data, and look at c_0 through c_9.&amp;nbsp; The count for "4" will be contained in c_4 (although counts of zero are not shown ... those variables will be missing instead of 0.)&lt;/P&gt;</description>
      <pubDate>Tue, 07 May 2019 02:35:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/To-find-count-and-matching/m-p/556640#M9866</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-05-07T02:35:35Z</dc:date>
    </item>
    <item>
      <title>Re: To find count and matching</title>
      <link>https://communities.sas.com/t5/New-SAS-User/To-find-count-and-matching/m-p/556778#M9886</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
x="1234567849";
run;
data want; 
 if _n_=1 then do;
   length k $ 1;
   declare hash h();
   h.definekey('k');
   h.definedone();
 end;
set have;
count=lengthn(x);
do i=1 to count;
 k=char(x,i);h.ref();
end;
unique_count=h.num_items;
drop k i;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 May 2019 14:04:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/To-find-count-and-matching/m-p/556778#M9886</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-05-07T14:04:37Z</dc:date>
    </item>
  </channel>
</rss>

