1
vote
$\begingroup$

English is not my first language. Here are my questions.

I am using proportions ((0.1, 0.25, 0.25, 0.4) to generate 4 classes of data (1 variable 4 levels) in SAS based on the code below,


data NativeBMI (drop = i) ;                     
array prob [4] (0.1,0.25,0.25,0.4); 

call streaminit(1234);                
do i = 1 to 100;                
BMI = rand("Table", of prob[*]);

output;                
end;       
run;

I have no problem with this code above. However, if I change the line from

    array prob [4] (0.1, 0.25, 0.25, 0.4);                                 
    call streaminit(1234);                
    do i = 1 to 100;                
    BMI = rand("Table", of prob[*]);

to

    array prob [4] z;
    call streaminit(1234);                
    do i = 1 to 100;                
    BMI = rand("Table", of prob[*]);

it doesn't work.

My goal is to use a set of proportions saved in an array elsewhere (in this example z) and pass that array (z) into the rand function

     rand("Table", of ...);

Thank you in advance.

$\endgroup$
0

1 Answer 1

0
votes
$\begingroup$

Arrays in SAS differ from arrays in other languages. In SAS arrays are used to temporarily group and refer to SAS variables. Arrays only exist for the duration of the data step where they are defined.

Therefore, you cannot "pass" an array between two datasteps. What you can do is to output your set of proportions in a temporary data set and then work by manipulating this data set.

For more information, here is a good short tutorial on arrays. You could also look up the documentation for the random function.

This is my first post, so let me know if this helps. Thanks, Jason.

$\endgroup$
0

Not the answer you're looking for? Browse other questions tagged or ask your own question.