楼主: previal
4059 16

用SAS可以产生这样的随机数吗? [推广有奖]

11
bobguy 发表于 2010-5-30 22:07:48
previal 发表于 2010-5-30 11:02
用SAS可以产生这样的随机数吗?比如产生只包括0 ,5 和10 的100个数,其概率分别为0.7,0.2和0.1
Yes!. Here is a brief explanation from online help.

The RANTBL function returns a variate that is generated from the probability mass function defined by p1 through pn . An inverse transform method applied to a RANUNI uniform variate is used.

A sample program attached below,

data t1;
seed=99612;
n=10000;   
p1=0.7;p2=0.2;p3=0.1;
array  a{3} _temporary_  (0,5,10) ;
do i = 1 to n;
    x=a{rantbl(seed,of p1-p3)};
    output;
end;
keep x;
run;

proc freq data=t1;
table x;
run;

12
hongxx 发表于 2010-6-1 09:29:18
11# bobguy

bobguy每次的代码都能让我学习到东西。
专业啊。

13
lovemanbbs 发表于 2010-6-1 09:34:24
6# jingju11
学习了~~

14
paladin112 发表于 2010-6-1 15:05:43
赞的,标记一下;

15
jingju11 发表于 2010-6-1 20:46:22
12# hongxx

Agree.
Indeed, she/he is knowledgeable and helpful.

In essence, it is to generate numbers following by a multinomial distribution.

16
suzhzh 发表于 2010-6-1 21:06:07
学习了,对的,主要是这个
问题的算法思想

17
sunshine87 发表于 2010-6-2 00:00:32
牛啊!又学习了一招!

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

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