全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
3784 2
2016-09-20
/* see the notes in the code below */
/* the idea is to add a variable of random number */
/* then sort the dataset by the random number of the new variable */
/* then output the specified number of observations to a new dataset */
/* this can also be done using a few data steps within a macro */

data allData;        /* sample dataset with 1100 observations as your original dataset */
   do id = 10001 to 11100;                  /* one ID variable */
       x = round(ranuni(12345)*100, 0.01);  /* x and y are two other variable */
       y = round(ranuni(12345)*100, 0.01);
      output;
   end;
run;

%macro samp;
    %let seed=1234;           /* initial seed used for generating random number */
    %do i = 1 %to 10;         /* loop: control the number of datasets to be generated */

      proc sql outobs=100;    /* PROC SQL for creating one sampling dataset */   
         create table sample&i. as  /* outobs= : control the number of observations sampled */
         select *
         from alldata
         order by ranuni(&seed);   /* creating a column of random number  */
      quit;                        /* for ordering the dataset */

      %let seed = %eval(&seed+2);  /* changing the seed for next sampling */
    %end;                          /* end of do-loop */  
%mend samp;
%samp






这段程序可以从1000个观测的数据集中,抽取100个观测的样本,随机抽取10次。程序时,人大论坛的一位大神写的,我copy了下,但对程序不太理解,order by 后面跟着一个随机变量,这个随机变量和数据集alldata没有任何关系,求问这是为啥呢

二维码

扫码加我 拉你入群

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

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

全部回复
2016-9-20 19:35:33
就是按照生成的随机数排序,这样就能达到每次随机抽取100条数据的效果
二维码

扫码加我 拉你入群

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

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

2016-9-21 08:49:57
liujunhzau524 发表于 2016-9-20 19:35
就是按照生成的随机数排序,这样就能达到每次随机抽取100条数据的效果
好像是数据集的随机排序
二维码

扫码加我 拉你入群

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

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

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

说点什么

分享

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