如何确定选择人口百分比的子集?

How to determine a subset selecting a percentage of population?

我需要计算人口的百分比。具体来说,我需要初始人口的 10% 才能确定新的子集。 我尝试使用

proc sql;
select time, 
      count(*)*0.1
from table1
group by 1;
quit;

它起作用了,因为我有我想要的人口百分比。但是,我很难找到一种方法来包含另一个条件 (where var1>0 and var2=24),其中变量来自原始数据集(即 var1var2 来自 table1)。 你知道我该怎么做吗?

假设您有 1,000 个项目(行),您希望从中抽取 10% 的随机样本。

Proc SURVEYSELECT 可能是 select 个样本的最佳方式。

data have;
  do id = 1 to 1000; output; end;
run;

proc surveyselect noprint data=have method=srs rate=10 out=want;
run;

SQLselect基于随机数的离子可以提供粗略的模拟,但不会产生精确的 10% 采样率。

proc sql;
  create table want as
  select id from have
  where rand('uniform') <= 0.10  %* roughly 10% of a uniform distribution;
;

还有其他方法,例如使用 k/n 算法的 DATA 步。

data want;
  call streaminit(123);

  do k=0.10*N by 0 while (k > 0);
    set have nobs=n;

    if rand('UNIFORM') <= k/n then do;
      k + (-1);
      output;
    end;
    n +(-1);
  end;

  stop;
run;