SAS中按比例分组的子数据

问题描述 投票:0回答:1

在此数据中,我需要按一定百分比对每个变量进行子集化。例如,

Obs Group Score
1     A    1
2     A    2
3     B    1
4     B    1
5     C    3
6     C    1
7     C    1
8     A    1
9     A    3
10    A    1
11    A    2
12    B    3
13    C    2

我需要将10磅作为子集。样本必须包含所有组,并且得分1优先。每个组都有一定百分比。假设A占50%,B占20%,C占30%。

我尝试使用proc surveyselect,但失败了。分配数与层数不同。

proc surveyselect data=example out=test sampsize=10;
strata group score/alloc=(0.5 0.2 0.3);
run;
sas subset sampling
1个回答
0
投票

我不太了解proc surveyselect,所以给了数据步骤版本。

data have;
    input Obs Group$ Score;
    cards;
1     A    1
2     A    2
3     B    1
4     B    1
5     C    3
6     C    1
7     C    1
8     A    1
9     A    3
10    A    1
11    A    2
12    B    3
13    C    2
;
run;

proc sort;
    by Group Score;
run;

data want;

    array _Dist_[3]$ _temporary_('A','B','C');
    array _Upper_[3] _temporary_(5,2,3);
    array _Count_[3] _temporary_;

    do i = 1 to rec;
        set have nobs=rec point=i;
        do j = 1 to dim(_Dist_);
            _Count_[j] + (Group=_Dist_[j]);
            if _Count_[j] <= _Upper_[j] and Group = _Dist_[j] then output;
        end;
    end;
    stop;
    drop j;
run;

© www.soinside.com 2019 - 2024. All rights reserved.