楼主: davincitom
1959 3

SAS 分层抽样的问题 [推广有奖]

  • 0关注
  • 2粉丝

大专生

75%

还不是VIP/贵宾

-

威望
0
论坛币
-8 个
通用积分
0.2498
学术水平
0 点
热心指数
5 点
信用等级
0 点
经验
531 点
帖子
57
精华
0
在线时间
49 小时
注册时间
2009-3-1
最后登录
2022-5-3

楼主
davincitom 发表于 2013-1-9 13:31:01 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
各位专家好,我现在有个抽样的问题想请教一下, 估计应该需要分层分布

我需要从我的客户信息数据库中取出,结果同时抽出满足

男 女比例:3:2

语言  英语 中文 :2:1

年龄段 :

18 - 45 :50%
46-55 :40%
+55 :10%

地理分布:

北京 :10%
上海:10%
广东:50%
新疆:30%


我该如果抽样呢?才能达到目的?

谢谢啦,十分感谢

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:分层抽样 地理分布 客户信息 年龄段 数据库 数据库 年龄段 广东

沙发
zkymath 在职认证  发表于 2013-1-10 10:59:30
分48层然后抽取分层样本
已有 1 人评分学术水平 热心指数 收起 理由
jingju11 + 1 + 1 观点有启发

总评分: 学术水平 + 1  热心指数 + 1   查看全部评分

藤椅
playmore 发表于 2013-1-10 12:42:34
使用proc surveyselect过程
然后在strata子句中加上你要进行分层的四个变量
至于比例可以写到一个dataset里,然后读进去
具体的看官方文档吧
playmore邀请您访问ChinaTeX论坛!!!进入ChinaTeX论坛

板凳
jingju11 发表于 2013-1-12 13:37:52
我编写如下的这种抽样sas程序,无需sorting数据;但是surveyselect基于sorted/grouped 数据。。。从程序效率而言,应该在稳定的基础并有改善。也可以参阅我的blog @ sample-allocation
京剧
http://blog.sina.com.cn/s/blog_a3a9263601019luq.html
http://blog.sina.com.cn/s/blog_a3a9263601019l0g.html
datasamplingFrom;
  call streaminit(12345);
  do obs =1 to 100000000;
    s1=rand('table',0.50);
    s2=rand('table',0.30);
    s3=rand('table',0.40);
    s4=rand('table',0.30,0.20,0.20);
   output;
  end;
run;

data samplingProps;
   length list $640.;
   do s1 =1 to 2;
     do s2 =1 to 2;
        do s3 =1 to 2;
           do s4 =1 to 4;
              _alloc_=  ifn(s1 =1,3/6,1-3/6)
                       *ifn(s2 =1,2/3,1-2/3)
                       *ifn(s3 =1,1/2,1-1/2)
                       *ifn(s4 in(14),2/8,ifn(s4 =3,3/8,1/8));
              list =catx(',',list,_alloc_);
              p ++_alloc_;
              output;
           end;
        end;
     end;
   end;
   *Maybe 1% tolerance;
   if fuzz(p)>=1.01 | fuzz(p) <=0.99 thenput"ERROR: Sum of props="p"(^=1),check the proportions.";
  callsymputx('list',list);
run;
%put &list;
%put ///sum of props=:%sysfunc(sum(&list));
data SamplingOut;
  call streaminit(12345);
  totSamples =1000;
  array t[2,2,2,4,2] _temporary_;
  if _n_ =1 then do;
    do p1 =1 tonobs1;
     set SamplingFrom point =p1 nobs =nobs1;
     t[s1,s2,s3,s4,1] ++1;
    end;
    do p2 =1 tonobs2;
     set SamplingProps point =p2 nobs =nobs2;
     t[s1,s2,s3,s4,2] =round(_alloc_*totSamples);
     totS ++t[s1,s2,s3,s4,2];
    end;
    puttotS;
    *adjusttotal sampling size when rounding problem occurs;
    *randomlydistribute rounding discrepancy to all strata;
    if totS^=totSamples then do i =1 toabs(totS-totSamples);   t[rand('table',.5),rand('table',.5),rand('table',.5),rand('table',.25,.25,.25),2]+(1*sign(totSamples-tots));
    end;
  end;
  set SamplingFrom;
  if t[s1,s2,s3,s4,2]>0 then ifrand('uniform') <= t[s1,s2,s3,s4,2]/t[s1,s2,s3,s4,1]then do;
   output;   
   t[s1,s2,s3,s4,2] +-1;
  end;

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-31 22:59