## How to count how many times value in a table repeated ?

Solved
Occasional Contributor
Posts: 6

# How to count how many times value in a table repeated ?

Hello , I'd like to ask a question, since I'm trying to acquire result which I want, and don't know how. I have a table, and what I'd like to do, is to count how many times, value in a colums repeats. Where can I find such an option?

Let's say I have

Col1Col2Col3Col4
115g
124b
134b
247d

.. and what I want to do with that is that kind of result:

there are 3 col2 that can be assigned to the value of col1 ,

there is 4 - which is number repeated most of col3 - 4 have a value of b

edit. Is the function Frequencies can count this? (how many times some value repeated?)

Accepted Solutions
Solution
‎02-13-2018 10:48 AM
Super User
Posts: 6,635

## Re: How to count how many times value in a table repeated ?

If you want something quick and dirty, you can use:

proc freq data=table1;

tables ShiftID * DepartmentID * Name / missing list out=counts;

run;

If you want something pretty, you'll have to take the output data set COUNTS and figure out how to print it.  It will already contain the data that you need, and it's just a matter of generating the proper report.

Good luck.

All Replies
Frequent Contributor
Posts: 89

## Re: Counting positions in a table

COUNTC function ??

can you give some examples or your test data step ??

Herman

Posts: 3,847

## Re: How to count how many times value in a table repeated ?

It is difficult to understand what you want but maybe something like this.

data a;
input col1-col3 col4 \$;
cards;
1  1  5  g
1  2  4  b
1  3  4  b
2  4  7  d
;;;;
run;
proc summary descend descendtypes chartype data=a;
class col:;
ways 1;

output out=counts;
run;
proc print;

run;

Occasional Contributor
Posts: 6

## Re: How to count how many times value in a table repeated ?

Ok I think now I will translate it better to you

I have that kind of table ^

What I need is that kind of table, but in some way made in SAS

Super User
Posts: 9,427

## Re: How to count how many times value in a table repeated ?

Well, they look like group bys to me:

data have;
shiftid=3;
employeeid=72;
departmentid=15;
name="Shipping and Recieving";
output;
employeeid=73;
departmentid=7;
name="Production";
output;
run;

proc sql;
create table WANT as
select  A.*,
B.*
from    (select SHIFTID,count(distinct EMPLOYEEID) as EMPLOYEES from WORK.HAVE group by SHIFTID) A
left join (select SHIFTID,DEPARTMENTID,NAME,count(distinct EMPLOYEEID) as NUM_EMPLOY from WORK.HAVE group by SHIFTID,DEPARTMENTID,NAME) B
on      A.SHIFTID=B.SHIFTID;
quit;

Posts: 3,847

## Re: How to count how many times value in a table repeated ?

Show data in data step with CARDS.  Not a picture.

Super User
Posts: 23,311

## Re: How to count how many times value in a table repeated ?

You'll need to modify the variable and table names but the following is

proc sort data=table1;

by shiftID employee department;

run;

proc freq data=table1;

by shiftID;

table department;

run;

Solution
‎02-13-2018 10:48 AM
Super User
Posts: 6,635

## Re: How to count how many times value in a table repeated ?

If you want something quick and dirty, you can use:

proc freq data=table1;

tables ShiftID * DepartmentID * Name / missing list out=counts;

run;

If you want something pretty, you'll have to take the output data set COUNTS and figure out how to print it.  It will already contain the data that you need, and it's just a matter of generating the proper report.

Good luck.

☑ This topic is solved.