BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
AndersS
Pyrite | Level 9

Hi! I want to use a statistical frequency distribution, that is not fully supported by SAS.

I know the exact functional expression.

I can generate  random numbers, that are uniformly distributed, using RAND('UNIFORM',0,1).

 

My question: How can I generate random numbers with this frequency distribution?

/Br Anders


Anders Sköllermo  Ph.D.,    anders.skollermo@one.se

Anders Sköllermo (Skollermo in English)
1 ACCEPTED SOLUTION

Accepted Solutions
mkeintz
PROC Star

Do you have a closed form expression for the inverse of the CDF for your distribution?   If so, generate a uniform random number for [0,1], and apply the inverse CDF to it.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

View solution in original post

6 REPLIES 6
mkeintz
PROC Star

Do you have a closed form expression for the inverse of the CDF for your distribution?   If so, generate a uniform random number for [0,1], and apply the inverse CDF to it.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
AndersS
Pyrite | Level 9

Hi!  Many thanks!    Yes I will sit down now and try it.  /Br Anders

 

Anders Sköllermo (Skollermo in English)
AndersS
Pyrite | Level 9

Hi!   I tested the GUMBEL distribution. It worked nicely. Below is my SAS-proghram. I think that it is quite OK. 
The value of DIFF is zero. Many thanks. /Br Anders

*************************************************************;
*** GUMBEL(0,1) - Quite OK ;

*** GUMBEL(1,2) - Quite OK ;
*************************************************************;

Data work.GUMBEL;
CALL STREAMINIT(2);
do I= 1 to 10;
rvalue = RAND('GUMBEL',1,2);
output;
end;
run;

Data work.MYGUMBEL;
CALL STREAMINIT(2);
do I= 1 to 10;
myunif = RAND('UNIFORM',0,1);
mygumbel = 1 - 2*LOG( -LOG(myunif) );
output;
end;
run;

data work.diff;
merge work.GUMBEL work.MYGUMBEL; by i;
run;

data work.diff;
set work.diff;
diff = rvalue - mygumbel;
output;
run;

Anders Sköllermo (Skollermo in English)
ballardw
Super User

Can you tell us what distribution or provide a link that defines the distribution?

 

Hard to provide any significant suggestions without details.

Rick_SAS
SAS Super FREQ

This is called the "inverse CDF method" for simulating samples from a formula for the CDF. You can read more about the inverse CDF method and how to implement it in SAS.

 

If you do not have the formula, you can generate samples from the empirical CDF. If you have the sull ECDF, this is called bootstrapping. If you only have a summary of the CDF (such as published quantiles), you can approximate the ECDF from the quantiles.

AndersS
Pyrite | Level 9

VERY GOOD reply by Rick!  Many Thanks!  / AndersS

Anders Sköllermo (Skollermo in English)

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 807 views
  • 3 likes
  • 4 in conversation