由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Statistics版 - 幼儿园分水果的SAS问题
相关主题
怎么去读proc genmod的output(关于multinomial)ASK FOR ONE SAS QUESTION
Multinomial Regression请教一个SAS 数据分配问题
请教一个sas问题如何在1,2,3,4,5中随机选出2个数来?
[合集] how to randomly draw 10% sample from a data set?再来问一个SAS问题
[合集] 请教一个percentile的问题 (SAS)SAS sampling的问题
读入SAS data set的问题SAS,如何从一个大的dataset里面提取部分记录
两个简单的SAS问题SAS 随机选择的问题
SAS random number generatior该怎么用呀?请教个SAS问题
相关话题的讨论汇总
话题: ranuni话题: 水果话题: 小朋友话题: fruit话题: 得到
进入Statistics版参与讨论
1 (共1页)
w********r
发帖数: 253
1
我有一个dataset,有50,000 obs,每个obs也就是一个row代表着一个幼儿园小朋友的
个人信息。没有重复。
这些小朋友的数据是从3个班级收集来的,分别叫做A班,B班,C班.
现在有7种水果(1,2,3,4,5,6,7)要随机random的分给小朋友们
唯一要求是希望每个班的分布如下:
A班
得到水果1的小朋友为10%
得到水果2的小朋友为5%
得到水果3的小朋友为15%
得到水果4的小朋友为10%
得到水果5的小朋友为20%
得到水果6的小朋友为25%
得到水果7的小朋友为15%
B班
得到水果1的小朋友为0%
得到水果2的小朋友为15%
得到水果3的小朋友为15%
得到水果4的小朋友为10%
得到水果5的小朋友为20%
得到水果6的小朋友为40%
得到水果7的小朋友为0%
C班
得到水果1的小朋友为5%
得到水果2的小朋友为5%
得到水果3的小朋友为25%
得到水果4的小朋友为10%
得到水果5的小朋友为20%
得到水果6的小朋友为35%
得到水果7的小朋友为5%
(这些数字不是真的比例,我只是想表示各个班的水果分配比例不一样,总和当然是每
班加起来100%)
现在问题
y****2
发帖数: 34
2
我想你可以这样做!
假设,A班有100个小朋友,你可以建一个variable叫id,然后随机的从1-100中不放回
的抽取1,2,。。。100, 然后给1-10的小朋友分水果1,11-15的分水果2,。。。 以
此类推。 试试? GL
y****2
发帖数: 34
3
思想就是:换个角度,不是把1-7随机分配,可以随机分配1,2,... 100的这个序列。
w********r
发帖数: 253
4
我晚上想来着
用proc surveyselect做
可惜我不知道怎么作不replacement的
你知道什么sas code可以写成你说的方法么?
多谢多谢~

【在 y****2 的大作中提到】
: 思想就是:换个角度,不是把1-7随机分配,可以随机分配1,2,... 100的这个序列。
t**i
发帖数: 688
5
50000 is not a small sample size.
Check if SAS has multinomial built-in function. If not, and if you want to
maintain the percentage rigidly, then you can do the following:
(1) For each class, assign a ranuni to each kid;
(2) sort them by the ranuni;
(3) According to the percentage, assign fruit.
Note: Kids' own ID should not be confused with their assigned ranuni numbers.
t**i
发帖数: 688
6
Another concern:
if ranuni(999)>0.9 then fruit=1;
else if ranuni (999) > 0.85 then fruit=2;
else if ranuni(999) > 0.7 then fruit = 3;
I am not good at SAS, therefore I am not sure the ranuni(999) values are the
same in these three lines.
b*******r
发帖数: 152
7
this is discrete prob dist, you can't use RANUNI. try RANTBL()
o****o
发帖数: 8077
8
check out title="Randomly Split SAS table exactly according to a given
probability vector" at http://sas-programming.blogspot.com
k*****t
发帖数: 186
9
You could do this:
1.assign random numbers to each kid in each class.
2.rank the kids according to random number.
3. assign fruits.
The idea is that each kid got a random number and you rank them according to
the random number, then use the rank to assign fruits. It should be quite
easy to program.
s********p
发帖数: 637
10
Just a simple test:
Your code:
data test1;
do i=1 to 50000;
if ranuni(999)>0.9 then fruit=1;
else if ranuni (999) > 0.85 then fruit=2;
else if ranuni(999) > 0.7 then fruit = 3;
else if ranuni(999) > 0.6 then fruit = 4;
else if ranuni(999) > 0.4 then fruit = 5;
else if ranuni(999) > 0.15 then fruit =6;
else fruit = 7;
output;
end;
run;
proc freq; tables fruit/missing; run;
Cumulative Cumulative
fruit Frequency Percent Frequency Percent


【在 w********r 的大作中提到】
: 我有一个dataset,有50,000 obs,每个obs也就是一个row代表着一个幼儿园小朋友的
: 个人信息。没有重复。
: 这些小朋友的数据是从3个班级收集来的,分别叫做A班,B班,C班.
: 现在有7种水果(1,2,3,4,5,6,7)要随机random的分给小朋友们
: 唯一要求是希望每个班的分布如下:
: A班
: 得到水果1的小朋友为10%
: 得到水果2的小朋友为5%
: 得到水果3的小朋友为15%
: 得到水果4的小朋友为10%

相关主题
读入SAS data set的问题ASK FOR ONE SAS QUESTION
两个简单的SAS问题请教一个SAS 数据分配问题
SAS random number generatior该怎么用呀?如何在1,2,3,4,5中随机选出2个数来?
进入Statistics版参与讨论
P****D
发帖数: 11146
11
Nice blog. Thanks. Is it yours?

【在 o****o 的大作中提到】
: check out title="Randomly Split SAS table exactly according to a given
: probability vector" at http://sas-programming.blogspot.com

o****o
发帖数: 8077
12
en

【在 P****D 的大作中提到】
: Nice blog. Thanks. Is it yours?
w********r
发帖数: 253
13
谢谢!!!
好奇怪啊,为啥结果不一样呢。。。

【在 s********p 的大作中提到】
: Just a simple test:
: Your code:
: data test1;
: do i=1 to 50000;
: if ranuni(999)>0.9 then fruit=1;
: else if ranuni (999) > 0.85 then fruit=2;
: else if ranuni(999) > 0.7 then fruit = 3;
: else if ranuni(999) > 0.6 then fruit = 4;
: else if ranuni(999) > 0.4 then fruit = 5;
: else if ranuni(999) > 0.15 then fruit =6;

w********r
发帖数: 253
14
great!!!
收藏了,谢谢~

【在 o****o 的大作中提到】
: check out title="Randomly Split SAS table exactly according to a given
: probability vector" at http://sas-programming.blogspot.com

p**********l
发帖数: 1160
15
blog 真不错。

【在 o****o 的大作中提到】
: check out title="Randomly Split SAS table exactly according to a given
: probability vector" at http://sas-programming.blogspot.com

1 (共1页)
进入Statistics版参与讨论
相关主题
请教个SAS问题[合集] 请教一个percentile的问题 (SAS)
用SAS sampling的一个问题读入SAS data set的问题
如何用SAS 生成一个组合变量?两个简单的SAS问题
SAS里怎么根据VALUE来选择需要OUTPUT的COLUMNSSAS random number generatior该怎么用呀?
怎么去读proc genmod的output(关于multinomial)ASK FOR ONE SAS QUESTION
Multinomial Regression请教一个SAS 数据分配问题
请教一个sas问题如何在1,2,3,4,5中随机选出2个数来?
[合集] how to randomly draw 10% sample from a data set?再来问一个SAS问题
相关话题的讨论汇总
话题: ranuni话题: 水果话题: 小朋友话题: fruit话题: 得到