sas怎么抽样
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/09 06:22:46
sas怎么抽样
sas怎么抽样
sas怎么抽样
1、利用SURVEYSELECT过程进行等比例分层抽样
* 利用SURVEYSELECT过程对数据集进行等比例分层抽样;
PROC SURVEYSELECT DATA = students out = samp1 method = srs samprate = .5 seed = 9876;
STRATA class gender;
RUN;
* 查看分层抽样的结果;
PROC FREQ DATA = samp1;
TABLES class * gender /NOPERCENT NOROW NOCOL;
RUN;
2、利用SURVEYSELECT过程进行不等比例分层抽样
* 利用SURVEYSELECT过程对数据集进行等不比例分层抽样;
PROC SURVEYSELECT DATA = students out = samp2 method = srs samprate = (.4 .6 .4 .6 .4 .6) seed = 9876;
STRATA class gender;
RUN;
* 查看分层抽样的结果;
PROC FREQ DATA = samp2;
TABLES class * gender /NOPERCENT NOROW NOCOL;
RUN;
3、利用SURVEYSELECT过程根据抽样数量进行分层抽样
* 利用SURVEYSELECT过程对数据集进行指定数量的分层抽样;
PROC SURVEYSELECT DATA = students out = samp3 method = srs n = (8 4 6 8 5 7) seed = 9876;
STRATA class gender;
RUN;
* 查看分层抽样的结果;
PROC FREQ DATA = samp3;
TABLES class * gender /NOPERCENT NOROW NOCOL;
RUN;
4、利用随机数函数RANUNI对数据集进行粗略划分
* 利用RANUNI函数将数据集粗略的划分为N=5份;
DATA s1 s2 s3 s4 s5;
SET students;
r = RANUNI(991889);
IF r