全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
1713 0
2010-01-31
Here is an example to use sortn in a random sample.

1)randomly select the obs number and store in an array
2)use direct access to read in data from bigdata.

This appoach may beat sas surveyselect procedure if the bigdata is BIG and sampling size is SMALL.


%let nobs=1000;
data bigdata;
   do i = 1 to &nobs;
       x=ranuni(123);
    output;
    end;
run;

%let size=40;
%let seed=78936;

data sample;
   array p[&nobs] _temporary_ ;
   array pk
  • pk1-pk&size;
       seed  = &seed;
       do  until(done=1);
          index=ceil(&nobs*ranuni(seed));
          if p[index] = . then do;
             p[index]=index;
             index2+1;
             pk[index2]=index;
             if index2=&size then done=1;
          end;
      end;

       call sortn(of pk
  • );

       do _i_ = 1 to &size;
          obs = pk[_i_];
          set bigdata point=obs;
          output;
          end;
       stop;
       drop pk: seed   done    index    index2 _i_;
       run;
       proc print; run;
  • 二维码

    扫码加我 拉你入群

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

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

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

    说点什么

    分享

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