## Vector parameters behaving as scalars in RANDGEN for Binomial distribution

Solved
Occasional Contributor
Posts: 13

# Vector parameters behaving as scalars in RANDGEN for Binomial distribution

Although the RANDGEN function should work on a vector of parameters, it doesn't give me the intended results. Even after generating a full matrix of parameter p in the code below by repeating the row vector (effectively a N*M matrix), the results clearly suggest that p is being taken as a scalar i.e. only the first element of p=0.1 from the matrix is used for whole matrix. I want to generate random numbers from a different distribution in each column.

%let N = 100;
%let M= 3;
proc iml;
call randseed(123);
x = j(&N,&M);
y = j(&N,&M);
p= j(1, &M);/*specify row vector*/
p= {.1 .2 .5}; /*Probability*/
p_mat = repeat(p, &N); /*Repeat probability parameter for j(&N,&M) matrix*/
call randgen(x, "Binomial",p_mat,&N );
x=x/&N;
mean=mean(x);
max=max(x);
print p,mean,max;
Quit;

RESULT:

p

 0.1 0.2 0.5

mean

 0.1014 0.1001 0.1075

max

 0.2

Accepted Solutions
Solution
‎11-22-2016 11:30 AM
SAS Super FREQ
Posts: 3,907

## Re: Vector parameters behaving as scalars in RANDGEN for Binomial distribution

Read the documenation for the RANDGEN subroutine, which states:

All parameters must be the same length. You cannot specify a scalar for one parameter and a vector for another. If you pass in parameter vectors that do not satisfy one of the above conditions, then the first element of each parameter is used.

``````proc iml;
call randseed(123);
x = j(&N,&M);
p = {.1 .2 .5}; /*Probability*/
N = repeat(&N, 1, &M);
call randgen(x, "Binomial", p, N);
x=x/&N;
mean=mean(x);
print p, mean;
``````

All Replies
Solution
‎11-22-2016 11:30 AM
SAS Super FREQ
Posts: 3,907

## Re: Vector parameters behaving as scalars in RANDGEN for Binomial distribution

Read the documenation for the RANDGEN subroutine, which states:

All parameters must be the same length. You cannot specify a scalar for one parameter and a vector for another. If you pass in parameter vectors that do not satisfy one of the above conditions, then the first element of each parameter is used.

``````proc iml;
call randseed(123);
x = j(&N,&M);
p = {.1 .2 .5}; /*Probability*/
N = repeat(&N, 1, &M);
call randgen(x, "Binomial", p, N);
x=x/&N;
mean=mean(x);
print p, mean;
``````
Occasional Contributor
Posts: 13

## Re: Vector parameters behaving as scalars in RANDGEN for Binomial distribution

[ Edited ]

Thanks a million. It worked.

☑ This topic is solved.