10334 31

怎么样用SAS来产生模拟数据集 [推广有奖]

  • 0关注
  • 4粉丝

教授

12%

还不是VIP/贵宾

-

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

相似文件 换一批

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币

求大神帮忙解决以下的SAS程序问题,试了很多次,实在是没有办法自己搞定。birth_data.xls


以上是一个birth_data的数据集。里面的变量包括patientage,一共有N个观测。现在我想要通过SAS产生一些模拟数据集。要求如下:


1)  在age的最大值和最小值之间随机产生0.1*N个模拟数。

2)  在birth_data随机抽取10%的干净数据,这些数据将被上一步中产生的模拟数据代替。随机抽取的次数为1000次,相应地,替代的次数也为一千次。这样可以得到1000个被抽取和替代后的birth_data的模拟数据集。

3)  得到的1000个模拟数据集以后,分别计算出这些模拟数据集中age的均值和方差,并且将这些均值和方差合并入格式如下的数据集中。

  

Simulation degree

  

Simulation dataset order



mean



std



0.1



1







0.1



2







0.1



3







0.1



4







0.1



5







0.1



... …







0.1



1000







二维码

扫码加我 拉你入群

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

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

关键词:模拟数据 数据集 怎么样 Simulation ulation 最大值 程序

birth_data.xls

249.5 KB

回帖推荐

yongyitian 发表于6楼  查看完整内容

大神帮我看一下呀。

使用道具

@yongyitian

使用道具

板凳
yongyitian 发表于 2014-3-18 23:10:36 |只看作者 |坛友微信交流群
2. 在birth_data随机抽取10%的干净数据,这些数据将被上一步中产生的模拟数据代替.

不明白这是什么意思,请举例说明。

使用道具

yongyitian 发表于 2014-3-18 23:10
2. 在birth_data随机抽取10%的干净数据,这些数据将被上一步中产生的模拟数据代替.

不明白这是什么意思 ...
就是在第一步里面我不是产生了10%*N个模拟的数据嘛,然后用这些模拟的数据随机的替代birth_data里面的10%的数据。

使用道具

地板
yongyitian 发表于 2014-3-19 11:20:07 |只看作者 |坛友微信交流群
  1. %macro simulation(rate=0.1);
  2.   Proc sql noprint;
  3.      select count(*), max(age_week), min(age_week) into
  4.                :n, :maxage,  :minage
  5.      from birth_data;
  6.   quit;

  7.   data _null_;
  8.     sample_size=int(&n*&rate);
  9.     call symputx('sample_size', sample_size);
  10.   run;

  11.   %let seed = 12345;

  12.   %do simu_num = 1001 %to 1010;
  13.   %let seed=%eval(&seed+&simu_num);

  14.   data simu_age;    /* step 1: create sample with random ages between (max and min) ages */
  15.        simu_num = &simu_num; put simu_num;
  16.         rate=&rate;
  17.      do i = 1 to &sample_size;
  18.          age_week = &minage + floor( (1+&maxage-&minage)*ranuni(&seed));
  19.         output;
  20.      end;
  21.      keep rate simu_num  age_week;
  22.   run;

  23.   proc sql noprint outobs=&sample_size;
  24.      create table sample as
  25.      select *
  26.      from birth_data
  27.      order by ranuni(&seed);
  28.   quit;
  29.       
  30.   data sample;
  31.     set sample;
  32.     set simu_age;
  33.   run;
  34.    
  35.   proc append base=all data=sample; run; %put loop=&simu_num;
  36.   %end;

  37.   proc sql;
  38.     create table final as
  39.     select distinct rate, simu_num, avg(age_week) as mean_age, std(age_week) as std_age
  40.     from all
  41.     group by simu_num
  42.     order by simu_num;
  43.   quit;
  44. %mend;
  45. %simulation(rate=0.1)
复制代码

使用道具

7
小宝爱波1314 发表于 2014-3-19 19:03:22 |只看作者 |坛友微信交流群
yongyitian 发表于 2014-3-19 11:20
NOTE: The query as specified involves ordering by an item that doesn't appear in its SELECT clause.
WARNING: Statement terminated early due to OUTOBS=398 option.
NOTE: Table WORK.SAMPLE created, with 398 rows and 2 columns.

NOTE: PROCEDURE SQL used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds



WARNING: Multiple lengths were specified for the variable AGE_week by input data set(s). This may cause truncation of data.
NOTE: There were 398 observations read from the data set WORK.SAMPLE.
NOTE: There were 398 observations read from the data set WORK.SIMU_AGE.
NOTE: The data set WORK.SAMPLE has 398 observations and 4 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


你好,我运行了一下您的代码,出现了这样的warning和error,您能看一下是不是我哪里出错了
NOTE: Appending WORK.SAMPLE to WORK.ALL.
WARNING: Variable patient_1 was not found on BASE file. The variable will not be added to the BASE file.
WARNING: Variable age_week has different lengths on BASE and DATA files (BASE 8 DATA 3).
ERROR: No appending done because of anomalies listed above. Use FORCE option to append these files.

使用道具

8
小宝爱波1314 发表于 2014-3-19 19:48:21 |只看作者 |坛友微信交流群
yongyitian 发表于 2014-3-19 11:20
NOTE: Appending WORK.SAMPLE to WORK.ALL.
WARNING: Variable patient_1 was not found on BASE file. The variable will not be added to the BASE file.
WARNING: Variable age_week has different lengths on BASE and DATA files (BASE 8 DATA 3).
ERROR: No appending done because of anomalies listed above. Use FORCE option to append these files.
还有这样的提示

使用道具

9
小宝爱波1314 发表于 2014-3-19 20:33:42 |只看作者 |坛友微信交流群
yongyitian 发表于 2014-3-19 11:20
您好,这个用data步做的话行不行呢?宏的话好像log提示很少呀

使用道具

10
yongyitian 发表于 2014-3-19 21:07:01 |只看作者 |坛友微信交流群
小宝爱波1314 发表于 2014-3-19 19:48
NOTE: Appending WORK.SAMPLE to WORK.ALL.
WARNING: Variable patient_1 was not found on BASE file ...
1. the warning is ok.
2. delete the ALL dataset before running the macro,
3. search proc append, or proc datasets -> append statement for details.

使用道具

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

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

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

GMT+8, 2024-4-24 15:10