SAS 随机抽样 [英] SAS Random Sampling
问题描述
在 SAS 中,我创建了一个程序,该程序将从数据集中随机抽取 50 个观察值并计算观察值的平均值.
In SAS I have created a program that will randomly take 50 observations from a data set and calculate a mean value for the observations.
data subset (drop=i samplesize);
samplesize=50;
obsleft=totobs;
do i=1 to samplesize;
obsnum=ceil(ranuni(0)*totobs);
set sashelp.baseball point=obsnum nobs=totobs;
output;
end;
stop;
run;
proc sql;
select mean(nHome) from subset;
quit;
我想编辑代码,以便生成 10 个独立的随机样本而不是一个(我知道 Proc SurverySelect 中的 reps=,但我不应该在这里使用它).谢谢
I would like to edit the code so it will produce 10 independent random samples instead of one (I am aware of the reps= in Proc SurverySelect, but I am not supposed to use it here). Thanks
推荐答案
k/n 算法选择固定数量的样本,每个样本的概率为 1/n.
The k/n algorithm selects a fixed number samples, each with a probability of 1/n.
%let SEED = 1234;
data mySurveySelection;
retain k 10; drop k;
length select_n_ 8;
set sashelp.baseball nobs=n;
if (ranuni(&SEED) <= k/n) then do;
k = k - 1;
select_n_ = _n_;
output;
end;
n = n - 1;
if n = 0 then stop;
run;
你没有要求证明选择确实是 1/n,所以我不会证明这一点.
You didn't ask for a proof that the selections are indeed 1/n, so I wont show that.
SurveySelect
通常用于任何生产级研究或代码库.
SurveySelect
is typically used in any production level study or code base.
这篇关于SAS 随机抽样的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!