user5626269
user5626269

Reputation:

SAS: Generating random values from an exponential

I need to add a new variable in an existing data set that is the simulation of an exponential. I need to set the lambda of this exponential so that the amount of values smaller than one will be between 9% and 14%.

Summarizing:

X ~ Expo(lambda)

There will be between 9% and 14% of values smaller than 1.

Upvotes: 0

Views: 1328

Answers (2)

Stu Sztukowski
Stu Sztukowski

Reputation: 12909

Use the rand() function with the 'exponential' argument; however, if you want between 9% and 14% of the values to be < 1, you'll need to solve for Lambda using the formula for the CDF of the exponential distribution. Personally, just to save time, I would simulate some values of Lambda and select the one that fits the criteria.

data findLambda;
    do lambda = 0.05 to 0.5 by 0.05;        
        do i = 1 to 5000;
            rand = rand('exponential')/lambda;
            LessThan_1_Flag = (rand < 1); 
            output;
        end;
   end;
run;

proc freq data=findLambda;
    by Lambda;
    tables LessThan_1_Flag / nocum norow nocol nofreq;
run;

You will find that a lambda value between 0.04 and 0.09 will generate what you are looking for.

Upvotes: 1

DomPazz
DomPazz

Reputation: 12465

RANEXP(seed) generates a random standard exponential. Divide that by lambda.

x=ranexp(seed)/lambda;

Upvotes: 0

Related Questions