全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
1918 3
2013-01-09
各位专家好,我现在有个抽样的问题想请教一下, 估计应该需要分层分布

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

男 女比例:3:2

语言  英语 中文 :2:1

年龄段 :

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

地理分布:

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


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

谢谢啦,十分感谢

二维码

扫码加我 拉你入群

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

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

全部回复
2013-1-10 10:59:30
分48层然后抽取分层样本
二维码

扫码加我 拉你入群

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

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

2013-1-10 12:42:34
使用proc surveyselect过程
然后在strata子句中加上你要进行分层的四个变量
至于比例可以写到一个dataset里,然后读进去
具体的看官方文档吧
二维码

扫码加我 拉你入群

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

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

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;
二维码

扫码加我 拉你入群

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

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

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群