楼主: harlon1976
3129 16

[原创博文] 编写无放回取数程序 [推广有奖]

  • 2关注
  • 27粉丝

版主

院士

54%

还不是VIP/贵宾

-

威望
1
论坛币
33781 个
通用积分
135.1232
学术水平
25 点
热心指数
39 点
信用等级
17 点
经验
59249 点
帖子
1928
精华
0
在线时间
4352 小时
注册时间
2005-8-27
最后登录
2025-12-9

楼主
harlon1976 发表于 2009-12-28 21:10:13 |AI写论文
100论坛币
请高手编写如下程序:从1-100个整数中随机无放回取20个数字.要求用SAS来编写.

最佳答案

xiaosanmao 查看完整内容

额 不要钱了友情赠送了 data a; do x=1 to 100; output; end; run; proc sql; create view temp as select *, RANUNI(0) as _ran_ from a order by calculated _ran_; quit; ...
关键词:程序

回帖推荐

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

The best and easy way is to use proc surveyselect. Here is the code. Method=srs specifies simple random sampling as the sample selection method. There are more options for different sampling methods that can be found from sas documents. proc surveyselect data=a method=srs n=20 out=b; run;

本帖被以下文库推荐

沙发
xiaosanmao 发表于 2009-12-28 21:10:14
额 不要钱了友情赠送了

data a;
do x=1 to 100;
output;
end;
run;
proc sql;                                                                     
    create view temp as                                                
       select *, RANUNI(0) as _ran_ from a                              
    order by calculated _ran_;                                                
quit;                                                                        
data aa1;                                                            
    set temp(obs = 100);                                                  
    drop _ran_;                                                               
run;
data _null_;
set aa1 end=a;
if a=1 then call symput('total',ceil(_n_/20));
run;
%macro test;
%do i=0 %to %eval(&total);
data out&i;
set aa1 ;
if  (_n_>20*&i and _n_<=20*(&i+1)) then output out&i;
%end;
proc sql;drop table out%eval(&total),a,aa1;quit;
%mend;
%test;

藤椅
chin 发表于 2009-12-28 21:32:04
Splus or R:sample(100,20)
最简单

板凳
laomm002 发表于 2009-12-28 21:35:55
人家要的是SAS哦

报纸
harlon1976 发表于 2009-12-28 21:48:32
是啊,高手帮忙啊

地板
harlon1976 发表于 2009-12-28 22:22:11
是一个数据集,是从1-100中随机选20个就行了,无放回,

7
xiaosanmao 发表于 2009-12-28 22:26:03
额 不要钱了 友情赠送了
data a;
do x=1 to 100;
output;
end;
run;
proc sql;                                                                     
    create view temp as                                                
       select *, RANUNI(0) as _ran_ from a                              
    order by calculated _ran_;                                                
quit;                                                                        
data aa1;                                                            
    set temp(obs = 20);                                                  
    drop _ran_;                                                               
run;

8
harlon1976 发表于 2009-12-28 22:34:05
谢谢,我怎么把100币给你呢

9
bobguy 发表于 2009-12-29 00:32:46
1# harlon1976

Here is an faster way to a random sample without replacement.

data t1;
   do i = 1 to 100;
      output;
   end;
run;

%let size=20;

data t2;
   set t1 nobs=nobs;
   if _n_=1 then do;
       _n=nobs;size=&size;
   end;
   if ranuni(-1) <=size/_n then do;
      size+(-1);
      output;
  end;
  _n+(-1);
  if size=0 then stop;
run;

proc print ;run;

10
yongyitian 发表于 2009-12-29 01:27:24
The best and easy way is to use proc surveyselect. Here is the code. Method=srs specifies simple random sampling as the sample selection method. There are more options for different sampling methods that can be found from sas documents.  

proc surveyselect data=a
      method=srs n=20
      out=b;
   run;
已有 1 人评分经验 论坛币 收起 理由
bakoll + 3 + 3 精彩帖子

总评分: 经验 + 3  论坛币 + 3   查看全部评分

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-1 04:15