全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
10397 15
2013-12-15
求各位大神,用SAS在大量的数据中随机抽取一部分数据,该怎么操作?比如我有10000条数据,想在这一万条数据里面随机抽取8000条,随机抽取100000次,产生100000个数据集,这种应该怎么操作呀?


二维码

扫码加我 拉你入群

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

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

全部回复
2013-12-16 09:22:55
复制代码
二维码

扫码加我 拉你入群

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

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

2013-12-16 09:26:07
yongyitian 发表于 2013-12-16 09:22
你好,可以解释一下你的思路么?授之以渔呀,嘿嘿
二维码

扫码加我 拉你入群

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

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

2013-12-16 09:56:08
小宝爱波1314 发表于 2013-12-16 09:26
你好,可以解释一下你的思路么?授之以渔呀,嘿嘿
/* 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
二维码

扫码加我 拉你入群

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

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

2013-12-25 08:48:08
请教在一个如下的数据集中随机多次抽取一部分(如80%)的数据,用SAS应该怎么做???
二维码

扫码加我 拉你入群

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

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

2013-12-25 09:25:29
小宝爱波1314 发表于 2013-12-25 08:48
请教在一个如下的数据集中随机多次抽取一部分(如80%)的数据,用SAS应该怎么做???
如果你的数据集alldata有10000条观测,把楼上code中的outobs=100 改成 outobs=8000

如果你的数据集alldata有n条观测,把楼上code中的 outobs=100 改成 outobs=int(0.8*n)
二维码

扫码加我 拉你入群

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

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

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

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