全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
5025 12
2010-03-11
请问要怎么产生以字母开头后随9位数字的5000个随机ID号?
程序应该怎么写?
请高人指教!谢谢!
二维码

扫码加我 拉你入群

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

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

全部回复
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;
二维码

扫码加我 拉你入群

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

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

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


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
二维码

扫码加我 拉你入群

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

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

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;
二维码

扫码加我 拉你入群

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

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

2010-3-12 12:28:49
学习到了
谢谢两位高人
二维码

扫码加我 拉你入群

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

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

2010-3-13 00:13:55
楼主我们班的啊 呵呵 跑着来问
二维码

扫码加我 拉你入群

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

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

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

说点什么

分享

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