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
Col1 | Col2 | Col3 | Col4 |
---|---|---|---|
1 | 1 | 5 | g |
1 | 2 | 4 | b |
1 | 3 | 4 | b |
2 | 4 | 7 | d |
.. 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?)
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.
COUNTC function ??
can you give some examples or your test data step ??
Herman
It is difficult to understand what you want but maybe something like this.
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
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;
Show data in data step with CARDS. Not a picture.
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;
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.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.