❶ SAS数据处理
DATA CHENGJI1;
INPUT NAME $ SEX $ MATH CHN GROUP;
CARDS;
李明 男 92 98 1
张红艺 女 89 106 1
王思明 男 86 90 1
;
RUN;
DATA CHENGJI2;
INPUT NAME $ SEX $ MATH CHN GROUP;
CARDS;
张聪 男 95 92 2
刘颖 女 98 101 2
高红 女 91 92 2
;
RUN;
DATA CHENGJI3;
INPUT NAME $ SEX $ MATH CHN GROUP;
CARDS;
赵强 男 93 99 3
李云芳 女 96 102 3
周闪 男 88 98 3
;
RUN;
*第二步;
DATA CHENGJI0;
SET CHENGJI1 CHENGJI2 CHENGJI3;
RUN;
*第三步;
DATA CHENGJI;
SET CHENGJI0;
AVG=MEAN(MATH,CHN);
RUN;
PROC SORT;
BY AVG;
RUN;
*第四步;
DATA MATH90;
SET CHENGJI0;
WHERE MATH>90;
RUN;
*第五步;
PROC SORT DATA=CHENGJI(KEEP=NAME GROUP AVG) OUT=LAST ;
BY GROUP AVG;
RUN;
DATA LAST;
SET LAST;
BY GROUP AVG;
IF FIRST.GROUP;
RUN;
*第六步;
PROC SORT DATA=CHENGJI0 OUT=MATH;
BY SEX;
RUN;
DATA MATH(KEEP=SEX AVG SUM_ALL);
SET MATH END=T;
BY SEX;
IF FIRST.SEX THEN DO;
I=0;
M=0;
END;
M+MATH;
I+1;
AVG=M/I;
J+1;
TOT+MATH;
IF LAST.SEX;
IF T THEN SUM_ALL=TOT;
RUN;
*第七步;
PROC SUMMARY DATA=CHENGJI0 NWAY;
VAR MATH;
OUTPUT OUT=A(DROP=_TYPE_ RENAME=(_FREQ_=N)) SUM=TOT;
RUN;
DATA DIF;
IF _N_=1 THEN SET A;
SET CHENGJI0;
AVG=TOT/N;
DIFF=AVG-MATH;
DROP TOT N;
RUN;
*第八步;
DATA EN;
INPUT EN @@;
CARDS;
80 84 85 86 82 87 96 75 52
;
RUN;
DATA ALL;
SET CHENGJI0;
SET EN;
RUN;
楼上这位是大牛,多向他学习学习
❷ SAS 分组排序后编号,取出每一组编号最大值
假设数据集名为datause,那么:
procsql;
createtabledatause_countingas
selectbl1,count(bl3)asGroup_Sizefromdatause
groupbybl1;
Createtablenewdatauseas
selecta.*,b.group__countingb
ona.bl1=b.bl1;
quit;