DATA Step, Macro, Functions and more

Count the number of individuals with the same characteristics

Accepted Solution Solved
Reply
Contributor
Posts: 33
Accepted Solution

Count the number of individuals with the same characteristics

Hello,

 

I would like to use Proc SQL.

 

I have a SAS table:

Capture d’écran (164).png

An individual with the same characteristics is the same person

 

 

I would like to count the number of individuals with same characteristics, and get this table:

 

Name   C1 C2 C3 Count

 

Thomas 1 2 3          3
Thomas 3 4 3           1          
Thomas 1 2 5          1
Fabien 1 2 3          2
Fabien 7 8 9          1

 


An individual with not the same characteristics, is not the same person, so we have 3 thomas and 2 fabien.

But the first thomas was recorded 3times, and  the first fabien 2 times.

 

 

Thanks for your help

 


Accepted Solutions
Solution
‎01-14-2018 03:01 PM
Trusted Advisor
Posts: 1,270

Re: Count the number of individuals with the same characteristics

Hi,

 

Something like this?

 

proc sql;

select *,count(*) as Count from have

group by name, c1,c2,c3;

quit;

View solution in original post


All Replies
Solution
‎01-14-2018 03:01 PM
Trusted Advisor
Posts: 1,270

Re: Count the number of individuals with the same characteristics

Hi,

 

Something like this?

 

proc sql;

select *,count(*) as Count from have

group by name, c1,c2,c3;

quit;

Super User
Posts: 23,321

Re: Count the number of individuals with the same characteristics

Try a basic PROC FREQ, TABULATE, MEANS/SUMMARY/UNIVARIATE. 

 

proc freq data=have noprint;

table name*c1*c2*c3 / list out=want;

run;

proc print data=want;
run;

WilliamB wrote:

Hello,

 

I would like to use Proc SQL.

 

I have a SAS table:

Capture d’écran (164).png

An individual with the same characteristics is the same person

 

 

I would like to count the number of individuals with same characteristics, and get this table:

 

Name   C1 C2 C3 Count

 

Thomas 1 2 3          3
Thomas 3 4 3           1          
Thomas 1 2 5          1
Fabien 1 2 3          2
Fabien 7 8 9          1

 


An individual with not the same characteristics, is not the same person, so we have 3 thomas and 2 fabien.

But the first thomas was recorded 3times, and  the first fabien 2 times.

 

 

Thanks for your help

 


 

PROC Star
Posts: 1,592

Re: Count the number of individuals with the same characteristics

If your data is a representative sample of your real, @Reeza 's suggestion is prolly the best and neat. SQl will remerge. Reemerge is fancy word for a 2nd pass. However, it's up to you. A bit more fun on a sunny sunday afternoon from me:

 

data have;
input (Name   C1 C2 C3) ($);
datalines;
Thomas 1 2 3          3
Thomas 3 4 3           1
Thomas 1 2 5          1
Fabien 1 2 3          2
Fabien 7 8 9          1
Thomas 1 2 3          3
Thomas 1 2 5          1
;

data _null_;
  if _N_ = 1 then do;
  if 0 then set have;
     declare hash h( );
      h.defineKey('Name','C1','C2','C3');
      h.defineData('Name','C1','C2','C3','count');
      h.defineDone();
	 end;
set have end=last;
if h.check() ne 0 then do;count=0;count+1;h.add();end;
else if h.find()=0 then do;count+1;h.replace();end;
if last then h.output(dataset:'want');
run;
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 150 views
  • 0 likes
  • 4 in conversation