请选择 进入手机版 | 继续访问电脑版
9399 15

[问答] 用SAS在大数据中抽取部分数据 [推广有奖]

  • 0关注
  • 4粉丝

教授

12%

还不是VIP/贵宾

-

威望
0
论坛币
6752 个
通用积分
15.8410
学术水平
18 点
热心指数
24 点
信用等级
15 点
经验
407 点
帖子
1190
精华
0
在线时间
995 小时
注册时间
2013-1-20
最后登录
2024-3-25

相似文件 换一批

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
求各位大神,用SAS在大量的数据中随机抽取一部分数据,该怎么操作?比如我有10000条数据,想在这一万条数据里面随机抽取8000条,随机抽取100000次,产生100000个数据集,这种应该怎么操作呀?


二维码

扫码加我 拉你入群

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

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

关键词:部分数据 大数据 怎么操作 数据集

本帖被以下文库推荐

yongyitian 发表于 2013-12-16 09:22:55 |显示全部楼层 |坛友微信交流群
  1. data allData;  /* create the sample dataset */
  2.    do id = 10001 to 11100;
  3.        x = round(ranuni(12345)*100, 0.01);
  4.        y = round(ranuni(12345)*100, 0.01);
  5.       output;
  6.    end;
  7. run;

  8. %macro samp;
  9.     %let seed=1234;
  10.     %do i = 1 %to 10;  
  11.       proc sql outobs=100;
  12.          create table sample&i. as
  13.          select *
  14.          from alldata
  15.          order by ranuni(&seed);
  16.       quit;
  17.       %let seed = %eval(&seed+2);
  18.     %end;
  19. %mend samp;
  20. %samp
复制代码

使用道具

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

使用道具

yongyitian 发表于 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

使用道具

请教在一个如下的数据集中随机多次抽取一部分(如80%)的数据,用SAS应该怎么做???

使用道具

yongyitian 发表于 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)

使用道具

yongyitian 发表于 2013-12-25 09:25
如果你的数据集alldata有10000条观测,把楼上code中的outobs=100 改成 outobs=8000

如果你的数据集 ...
假设我抽样n次,可以得到n个数据集,然后计算每个数据集中的平均数和标准差等变量,把平均数和标准差放到另外n个不同的数据集中,然后合并这n个数据集,在宏里面怎么样操作呀?我试了很多次,都没写出代码。

使用道具

yongyitian 发表于 2013-12-25 09:25
如果你的数据集alldata有10000条观测,把楼上code中的outobs=100 改成 outobs=8000

如果你的数据集 ...
%macro samp;
    %let seed=1234;           /* initial seed used for generating random number */
    %do i = 1 %to 100;         /* 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 */
proc means data=sample&i mean std;
var x y;
output out=distribution&i mean=xx yy std=xxstd yystd;
run;

      %let seed = %eval(&seed+2);  /* changing the seed for next sampling */
    %end;                          /* end of do-loop */  
%mend samp;
%samp
就是我想把这些distribution(标红)的数据集合并起来,成为一个数据集

使用道具

yongyitian 发表于 2013-12-25 09:25
如果你的数据集alldata有10000条观测,把楼上code中的outobs=100 改成 outobs=8000

如果你的数据集 ...
data allData;  /* create the sample dataset */
   do id = 10001 to 11100;
       x = round(ranuni(12345)*100, 0.01);
       y = round(ranuni(12345)*100, 0.01);
      output;
   end;
run;
您发给我的这段代码,我的理解是产生与观测相同的随机种子数,然后把种子数排序,取前面80%的数,对吗?

使用道具

yongyitian 发表于 2013-12-25 10:06:03 |显示全部楼层 |坛友微信交流群
小宝爱波1314 发表于 2013-12-25 09:35
data allData;  /* create the sample dataset */
   do id = 10001 to 11100;
       x = round(ranu ...
  1. /* alldata 是生成的模拟数据集, 12345生成模拟数据集时用的种子。 */
  2. /* try this again */

  3. data allData;  /* create the sample dataset */
  4.    do id = 10001 to 11100;
  5.        x = round(ranuni(12345)*100, 0.01);
  6.        y = round(ranuni(12345)*100, 0.01);
  7.       output;
  8.    end;
  9. run;

  10. %macro samp;
  11.     %let seed=1234;
  12.     %do i = 1 %to 10;  
  13.       proc sql outobs=100;
  14.          create table sample&i. as
  15.          select *
  16.          from alldata
  17.          order by ranuni(&seed);
  18.       quit;

  19.       proc sql;     /* for calcylating mean and std */
  20.          create table meanstd&i as
  21.          select avg(x) as mean_x, std(x) as std_x, avg(y) as mean_y, std(y) as std_y
  22.       from sample&i;
  23.       quit;
  24.       proc append base = final data=meanstd&i;   /* append mean and std together */
  25.       run;
  26.       %let seed = %eval(&seed+2);
  27.     %end;
  28. %mend samp;
  29. %samp
复制代码

使用道具

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

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-3-28 21:34