[having count() 구문] 그룹별 건수 계산 후 계산 값이 특정 값 이상인 경우 - 50 (오라클 SQL, R, Python, SAS)
by 기서무나구물2021. 8. 16.
포스팅 목차
50. Display the various jobs along with total number of employees in each job. The output should contain only those jobs with more than three employees.
%%SAS sas
PROC SQL;
CREATE TABLE STATSAS_1 AS
select job, count(*) AS EMP_CNT
from emp
group
by 1
having count(*)>3;
QUIT;
PROC PRINT;RUN;
Results
OBS
job
EMP_CNT
1
CLERK
4
2
SALESMAN
4
9. SAS Data Step
Proc Summary 프로시져
SAS Programming
%%SAS sas
PROC SUMMARY DATA=EMP NWAY;
CLASS job;
VAR SAL;
OUTPUT OUT=STATSAS_2(DROP=_: WHERE=(EMP_CNT > 3)) N=EMP_CNT;
RUN;
PROC PRINT;RUN;
Results
OBS
job
EMP_CNT
1
CLERK
4
2
SALESMAN
4
SAS Programming
%%SAS sas
PROC SORT DATA=EMP OUT=EMP_1;
BY job;
RUN;
DATA STATSAS_3(WHERE=(EMP_CNT > 3));
SET EMP_1;
BY job;
IF FIRST.job THEN EMP_CNT = 1;
ELSE EMP_CNT + 1; * EMP_CNT = EMP_CNT + SAL;
IF LAST.job; * IF LAST.JOB THEN OUTPUT STATSAS_3;
KEEP job EMP_CNT;
RUN;
PROC PRINT;RUN;
댓글