首页 养生问答 疾病百科 养生资讯 女性养生 男性养生

sas怎么抽样

发布网友 发布时间:2022-04-26 10:14

我来回答

1个回答

热心网友 时间:2022-05-03 10:43

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(9918);
IF r<0.2 THEN OUTPUT s1;
ELSE IF r<0.4 THEN OUTPUT s2;
ELSE IF r<0.6 THEN OUTPUT s3;
ELSE IF r<0.8 THEN OUTPUT s4;
ELSE OUTPUT s5;
DROP r;
RUN;
5、利用随机数函数RANUNI对数据集进行精确划分
* 根据数据集创建视图students_v,增加随机数列;
DATA students_v /view=students_v;
SET students;
srt = RANUNI(9990);
RUN;
* 按照随机数列对数据集进行排序,创建数据集students_srt,删除随机数列;
PROC SORT DATA = students_v OUT = students_srt(DROP = srt);
BY srt;
RUN;
* 将数据集精确地划分为N=5份;
DATA s1 s2 s3 s4 s5;
RETAIN per ;
SET students_srt NOBS= total;
IF _N_ = 1 THEN per = INT(total/5);
if _N_<= per then output s1;
ELSE IF _N_<= 2 * per THEN OUTPUT s2;
ELSE IF _N_<= 3 * per THEN OUTPUT s3;
ELSE IF _N_<= 4 * per THEN OUTPUT s4;
ELSE OUTPUT s5;
DROP per;

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com