mardi 21 février 2017

SAS generate random distributions by group

I would like to generate a random number between 0 and 1 by group - in this case based upon a and b - i.e. a uniform distribution for each combination.

/* Create groups */
data test ;
input a b ;
datalines ;
1 1
1 1
1 2
1 2
1 2
2 1
2 1
2 2
2 2
2 2
;

/* Generate random number between 0 and 1 */
data test2 ;
set test ;
random = ranuni(5039) ;
run ;

In the table test2 produced, for the group a=1 b=1 both values of random are less than 0.3 and thus do not follow a uniform distribution (obviously the sample is very small) I tried adding by a b ; yet this produces the same table.

How can I create the required distribution by group?




Aucun commentaire:

Enregistrer un commentaire