Edit

SAS: Rand Function

2016/12/023

 As the detail of a sample SAS data described in the previous article of 'SAS: Sample Data (Demographic Characteristics),'  this article argues the 'Rand Function' which can generate random numbers with various distribution.  In my understanding, we can define 20 patterns!  Although other functions, such as 'rannor', are available for generating random variables, I consider that this function is easy to generate them.  So, for my programming memo, I will show a sample program and output as follows.

PROGRAM


DATA DATA ;
CALL STREAMINIT(12345) ; *** DEFINE A SEED. ***;

*---RAND('BERNOULLI',p)--- ;

A01='BERNOULLI     '; B01=rand('BERNOULLI',.75         );

*---RAND('BETA',a,b)---;
A02='BETA'          ; B02=rand('BETA',3,0.1            );

*---RAND('BINOMIAL',p,n)---;
A03='BINOM'         ; B03=rand('BINOM',0.75,10         );

*---RAND('CAUCHY')--- ;
A04='CAUCHY'        ; B04=rand('CAUCHY'                );

*---RAND('CHISQUARE',df)--- ;
A05='CHISQUARE'     ; B05=rand('CHISQUARE',22          );

*---RAND('ERLANG',a)---;
A06='ERLANG'        ; B06=rand('ERLANG', 7             );

*---RAND('EXPONENTIAL')---;
A07='EXPONENTIAL'   ; B07=rand('EXPONENTIAL'           );

*---RAND('F',n, d)--- ;
A08='F'             ; B08=rand('F',12,322              );

*---RAND('GAMMA',a)--- ;
A09='GAMMA'         ; B09=rand('GAMMA',7.25            );

*---RAND('GEOMETRIC',p)---;
A10='GEOMETRIC'     ; B10=rand('GEOMETRIC',0.02        );

*---RAND('HYPER',N,R,n)---;
A11='HYPERGEOMETRIC'; B11=rand('HYPERGEOMETRIC',10,3,5 );

*---RAND('LOGNORMAL')---;
A12='LOGNORMAL'     ; B12=rand('LOGNORMAL'             );

*---RAND('NEGBINOMIAL',p,k)---;
A13='NEGBINOMIAL'   ; B13=rand('NEGBINOMIAL',0.8,5     );

*---RAND('NORMAL',<,THETA,RAMBDA> )---;
A14='NORMAL'        ; B14=rand('NORMAL'                );

*---RAND('POISSON',m)--- ;
A15='POISSON'       ; B15=rand('POISSON',6.1           );

*---RAND('T',df)--- ;
A16='T'             ; B16=rand('T',4                   );

*---RAND('TABLE',p1,p2, ...)---;
A17='TABLE'         ; B17=rand('TABLE',.2,.5           );

*---RAND('TRIANGLE',h)--- ;
A18='TRIANGLE'      ; B18=rand('TRIANGLE',0.7          );

*---RAND('UNIFORM')---;
A19='UNIFORM'       ; B19=rand('UNIFORM'               );

*---RAND('WEIBULL',a,b)--- ;
A20='WEIBULL'       ; B20=rand('WEIBULL',0.25,2.1      );

/* TRANSPOSEING ROW AND COLUMN*/
ARRAY RAND_O1{*} A01-A20 ;
ARRAY RAND_O2{*} B01-B20 ;

DO I=1 TO 20 ;
  DISTRIBUTION =RAND_O1{I} ;
  EXAMPLE_OUT  =RAND_O2{I};
  OUTPUT ;
END ;
KEEP I DISTRIBUTION EXAMPLE_OUT;
RUN ;

OUTPUT

SOURCE LINK: SAS_HP


Search This Blog