❶ 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;