楼主: 少呃
5099 12

求助!关于SAS中产生随机数的问题 [推广有奖]

  • 0关注
  • 0粉丝

小学生

0%

还不是VIP/贵宾

-

威望
0
论坛币
15 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
23 点
帖子
2
精华
0
在线时间
5 小时
注册时间
2010-1-2
最后登录
2010-6-21

楼主
少呃 发表于 2010-3-11 22:38:07 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
请问要怎么产生以字母开头后随9位数字的5000个随机ID号?
程序应该怎么写?
请高人指教!谢谢!
二维码

扫码加我 拉你入群

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

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

关键词:随机数 求助 SAS 随机数

回帖推荐

bobguy 发表于4楼  查看完整内容

Here is the one. I do a little trick to manuplate a seed in SAS. The results look good. Note sas seeds will repeat after 2**32-1 if I remember it correct. You can write your own by finding out the random uniform generation. %let n=50000; data o; seed=ceil(ranuni(123)*100) ; do while(1); call ranuni(seed, r3); x= int(log10(seed)); if x

jingju11 发表于3楼  查看完整内容

Generating 9-digit random numbers (integers) is somewhat time-consuming. We need to make sure that they are unique and selected from 1 to 1E9-1 by equal chance. JingJu

crackman 发表于2楼  查看完整内容

data test; do i=1 to 5000; retain seed 185634382; call ranuni(seed,random); output; end; run; data a(drop=seed i random random1 random2); set test; random1=random*100000; format random1 5.; random2=put(random1,5.); ID="a"||random2; run; proc print; run;

本帖被以下文库推荐

沙发
crackman 发表于 2010-3-11 23:41:07
data test;
do i=1 to 5000;
retain seed  185634382;
call ranuni(seed,random);
output;
end;
run;
data a(drop=seed i random random1 random2);
set test;
random1=random*100000;
format random1 5.;
random2=put(random1,5.);
ID="a"||random2;
run;
proc print;
run;
已有 1 人评分经验 论坛币 收起 理由
bakoll + 3 + 3 精彩帖子

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

藤椅
jingju11 发表于 2010-3-12 01:27:01
少呃 发表于 2010-3-11 22:38
请问要怎么产生以字母开头后随9位数字的5000个随机ID号?
程序应该怎么写?
请高人指教!谢谢!

  1. DATA RAW;
  2. DO X = 1 TO 1E9-1;
  3.   OUTPUT;
  4. END;
  5. RUN;
  6. PROC SURVEYSELECT DATA=RAW
  7.       METHOD=SRS N = 5000 SEED = 1 OUT = SampleSRS;
  8. run;
  9. DATA RANDOM_ID;
  10. SET SampleSRS;
  11. ID = 'A'||PUT(X, Z9.);
  12. DROP X;
  13. RUN;
复制代码


Generating 9-digit random numbers (integers) is somewhat time-consuming. We need to make sure that they are unique and selected from 1 to 1E9-1 by equal chance.
JingJu
已有 2 人评分经验 论坛币 热心指数 收起 理由
bakoll + 3 + 3 精彩帖子
dybwall1234 + 1 这个运行会卡 我把数量改小了可以生成的是从A000000001到99的串

总评分: 经验 + 3  论坛币 + 3  热心指数 + 1   查看全部评分

板凳
bobguy 发表于 2010-3-12 12:21:14
少呃 发表于 2010-3-11 22:38
请问要怎么产生以字母开头后随9位数字的5000个随机ID号?
程序应该怎么写?
请高人指教!谢谢!
Here is the one. I do a little trick to manuplate a seed in SAS. The results look good. Note sas seeds will repeat after 2**32-1 if I remember it correct.

You can write your own by finding out the random uniform generation.



%let n=50000;
data o;
  seed=ceil(ranuni(123)*100)  ;
  do while(1);
    call ranuni(seed, r3);
    x= int(log10(seed));
    if x<9 then do;
      n+1;
      id='a'||put(seed,z9.);
      if seed<100000000 then c=1;
      else if seed<200000000 then c=2;
      else if seed<300000000 then c=3;
      else if seed<400000000 then c=4;
      else if seed<500000000 then c=5;
      else if seed<600000000 then c=6;
      else if seed<700000000 then c=7;
      else if seed<800000000 then c=8;
      else if seed<900000000 then c=9;
      else c=10;
      output;
      if n=&n then stop;
     end;
  end;
run;

proc freq data=o;
table c;
run;

proc sort data=o nodupkey;by seed;run;
已有 1 人评分经验 论坛币 收起 理由
bakoll + 3 + 3 精彩帖子

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

报纸
crackman 发表于 2010-3-12 12:28:49
学习到了
谢谢两位高人

地板
dybwall1234 发表于 2010-3-13 00:13:55
楼主我们班的啊 呵呵 跑着来问

7
08liurenxing 发表于 2010-3-13 07:40:21
受教了,谢谢高手

8
dybwall1234 发表于 2010-3-13 16:00:45
jingju11 发表于 2010-3-12 01:27
少呃 发表于 2010-3-11 22:38
请问要怎么产生以字母开头后随9位数字的5000个随机ID号?
程序应该怎么写?
请高人指教!谢谢!

  1. DATA RAW;
  2. DO X = 1 TO 1E9-1;
  3.   OUTPUT;
  4. END;
  5. RUN;
  6. PROC SURVEYSELECT DATA=RAW
  7.       METHOD=SRS N = 5000 SEED = 1 OUT = SampleSRS;
  8. run;
  9. DATA RANDOM_ID;
  10. SET SampleSRS;
  11. ID = 'A'||PUT(X, Z9.);
  12. DROP X;
  13. RUN;
复制代码
Generating 9-digit random numbers (integers) is somewhat time-consuming. We need to make sure that they are unique and selected from 1 to 1E9-1 by equal chance.
JingJu
这个很坏啊 运行卡机 产生大量临时文件

9
少呃 发表于 2010-3-13 16:25:02
对啊,上面那个一运行就把盘写满了。。
不过还是谢谢各位的指教啦!

10
jingju11 发表于 2010-3-13 22:32:51
dybwall1234 发表于 2010-3-13 16:00
jingju11 发表于 2010-3-12 01:27
少呃 发表于 2010-3-11 22:38
请问要怎么产生以字母开头后随9位数字的5000个随机ID号?
程序应该怎么写?
请高人指教!谢谢!

  1. DATA RAW;
  2. DO X = 1 TO 1E9-1;
  3.   OUTPUT;
  4. END;
  5. RUN;
  6. PROC SURVEYSELECT DATA=RAW
  7.       METHOD=SRS N = 5000 SEED = 1 OUT = SampleSRS;
  8. run;
  9. DATA RANDOM_ID;
  10. SET SampleSRS;
  11. ID = 'A'||PUT(X, Z9.);
  12. DROP X;
  13. RUN;
复制代码
Generating 9-digit random numbers (integers) is somewhat time-consuming. We need to make sure that they are unique and selected from 1 to 1E9-1 by equal chance.
JingJu
这个很坏啊 运行卡机 产生大量临时文件
Really? I run it about 3-5 minutes and had no obvious problem. About the temporary files, I don't get it. Can you list it out? If you had better way to do that, why don't share it?

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-29 19:58