楼主: 墨岚
2492 14

[问答] 为什么rantbl()对cards里的分数概率不认识? [推广有奖]

  • 0关注
  • 0粉丝

本科生

86%

还不是VIP/贵宾

-

威望
0
论坛币
520 个
通用积分
7.5801
学术水平
0 点
热心指数
1 点
信用等级
0 点
经验
965 点
帖子
48
精华
0
在线时间
158 小时
注册时间
2011-5-30
最后登录
2025-5-1

楼主
墨岚 发表于 2013-5-2 15:28:31 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
程序如下:data e;       
input p1 p2;
do i=1 to 16;
a=rantbl(100,p1,p2);
end;
cards;
1/2 1/2
;
run;

日志里显示数据行“有对“p1”无效的数据”,不读。
但是直接用 a=rantbl(100,1/2,1/2);就可以。
因为我的概率有40多项,所以想用cards输入,请问高手这个怎么解决呢?
二维码

扫码加我 拉你入群

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

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

关键词:rantbl cards card RAN Ant 程序

要踏实,也要巧劲,唯独不要怨艾。

沙发
墨岚 发表于 2013-5-2 16:21:18
问题不在rantbl,而是datalines/cards不认识这种分数表示。。那该怎么表示啊?
要踏实,也要巧劲,唯独不要怨艾。

藤椅
jingju11 发表于 2013-5-3 08:11:27
墨岚 发表于 2013-5-2 16:21
问题不在rantbl,而是datalines/cards不认识这种分数表示。。那该怎么表示啊?
One more reason for the problem, is the function won't take characters as its arguments although you can read the fractions from cards. In fact, a more elegant way to do that is to load/write the values to a macro variable. That will give you a lot more flexibility on programing. Jingju
  1. data have;
  2.         input (frac1-frac4) (4* $ :12.);
  3.         array p[4] _temporary_; array frac[4];
  4.         do i =1 to 4;
  5.                 if index(frac[i], '/') then p[i] =scan(frac[i],1, '/')/scan(frac[i],2, '/');
  6.                 else p[i] =frac[i] +0;
  7.         end;
  8.         do i =1 to 100;
  9.                 a =rantbl(123,of p[ * ]); output;
  10.         end;
  11. cards;
  12. .1 1/2 1/3 1/15
  13. ;
复制代码

板凳
墨岚 发表于 2013-5-3 10:17:25
jingju11 发表于 2013-5-3 08:11
One more reason for the problem, is the function won't take characters as its arguments although y ...
Thanks! The idea that input fractions as characters solves my problem indeed('_temorary_' is very useful!). But I recognize code like "a =rantbl(123,.1,1/2,1/3,1/15);" can be read as well .
By the way, can rantbl() generate several radom numbers, instead of one number at a time? I need different numbers in one repeat...
要踏实,也要巧劲,唯独不要怨艾。

报纸
jingju11 发表于 2013-5-3 10:31:04
Yeah, it takes fractions (1/2)but not the character ('1/2').
I don't think think so. as you know, sas function returns one value at a time. If you want to have multiple columns, just insert one more loop, like:
  1. array t[3] a  b c;
  2. do i =1 to 100;
  3.    do j =1 to 3;
  4.       t[i] =rand('tabled', of p{*});
  5.    end;
  6.    output;
  7. end;
复制代码

地板
墨岚 发表于 2013-5-3 10:43:52
jingju11 发表于 2013-5-3 10:31
Yeah, it takes fractions (1/2)but not the character ('1/2').
I don't think think so. as you know,  ...
That's what I did.. Unfortunately, these three numbers are in fact three samples but not three numbers in one sample which is preferred. Still thank u for the confirmation!
要踏实,也要巧劲,唯独不要怨艾。

7
jingju11 发表于 2013-5-3 10:56:12
random numbers not distinguished by samples. i tend to understand your samples as different datasets. using output in different positions will give you different forms of data...

8
墨岚 发表于 2013-5-3 11:29:13
jingju11 发表于 2013-5-3 10:56
random numbers not distinguished by samples. i tend to understand your samples as different datasets ...
比如现在有一个20项的多项分布,按照这个分布取得一批随机数不是我的最终目的,这批随机数实际上是我想做出的另一个分布的一个样本,因为这个样本是符合前面的多项分布的。每次抽样就是按照这个分布抽取固定数目的随机数比如10个,因为模型的原因这10个数不能重复,类似于一次不放回的抽样,所以我想问可否一次抽取多个不重复的随机数..rantbl的sas帮助里也没有看到这方面的说明.
要踏实,也要巧劲,唯独不要怨艾。

9
yongyitian 发表于 2013-5-3 12:09:15
There is a tricky way to avoid your input fraction problem. It may also give you more options to programm with array or loop.

Or just type a few more letters and numbers, it could save your time working out how the macro or array, or loops could make the program looks pretty.
data e;
input n1 d1 n2 d2 n3 d3 n4 d4 n5 d5;
     p1 = n1/d1;
         p2 = n2/d2;
         p3 = n3/d3;
         p4 = n4/d4;
         p5 = n5/d5;
         do i=1 to 16;
    a=rantbl(100,p1,p2,p3,p4,p5);
        output;
        end;
datalines;
1 2 1 3 1 4 1 5 1 6
;

10
墨岚 发表于 2013-5-3 12:26:05
yongyitian 发表于 2013-5-3 12:09
There is a tricky way to avoid your input fraction problem. It may also give you more options to pro ...
Tricky indeed.
要踏实,也要巧劲,唯独不要怨艾。

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

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