I am new to sas programming and am having difficulty trying to perform a certain function. I want to generate 4 random numbers from a given range, without replacement, based on given probabilities that each number will be chosen, and I want to perform 2000 repetitions of this. I have been searching trying to find a way to do this, however everywhere just says to put rand("normal") or rand("uniform") but this will not perform my intended task. I also know the theta and sigma for each of the 4 numbers based on 1800 actual past observations. Any help on how I might perform this would be great.
Thanks
p.s. I am using sas university edition
If I may offer some friendly advice, I suggest
1. Talk to your advisor/professor. He/She wants you succeed.
2. Consider changing to the model I proposed. In that model, you would count how many times each ball has EVER appeared (regardless of whether it was the first, second, ... or fifth ball). That is a standard probability model in which the probability of drawing each ball is constant and the draws are independent.
If you attempt the simpler project, it will still be challenging and you will still learn a lot about SAS programming and simulation. However, the simpler problem will be more tractable for someone with your level of experience.
Good luck!
What kind of range you do need, provide some example.
What is your theta supposed to represent from which distribuion? if from a Normal distribution you can specify the parameter
x=rand('NORMAL',theta,sigma); if theta is your mean and sigma the standard deviation that you want have your sample represented from.
There is also rand('TABLE'). You provide a list of probabilities.
x=rand('TABLE', 0.1,0.2,0.5,0.2); would returen a 1 with probability .1, a 2 with probability .2, a 3 with probability .5 or a 4 with probability .2
p= 1/6;
x=rand('TABLE',p,p,p,p,p,p); does a good job of simulating a 6-sided die.
There are multiple ways to map the 1,2,3, to other values if needed.
If you need result ranges sometimes you have to recalculate but specific approaches may depend on what you are attempting.
Are you talking about a mixture of normal distributions? In a mixture, the parameters are chosen with a specified probability, then a random value is drawn from the appropriate normal distribution. See "Generate a random sample from a mixture distribution" for a discussion and SAS code.
If the i_th ball was drawn k_i times, then the empirical probability for is p_i = k_i / (5*1800).
You should create a SAS data set that has two coloumns: the ball number and the empirical probability.
You then want to draw a sample (without replacement) of size 5 with those (unequal) probabilities.
See the article "Four essential sampling methods in SAS" which gives the syntax for using PROC SURVEYSELECT or PROC IML to sample according to this scheme. See the upper right corner of the table in the article for the syntax.
4. When is the project due?
If I may offer some friendly advice, I suggest
1. Talk to your advisor/professor. He/She wants you succeed.
2. Consider changing to the model I proposed. In that model, you would count how many times each ball has EVER appeared (regardless of whether it was the first, second, ... or fifth ball). That is a standard probability model in which the probability of drawing each ball is constant and the draws are independent.
If you attempt the simpler project, it will still be challenging and you will still learn a lot about SAS programming and simulation. However, the simpler problem will be more tractable for someone with your level of experience.
Good luck!
How many records do you have from the lottery where the rules did not change? I am thinking of the PowerBall where they have increased the numbers of the balls in both the main numbers and in the Power ball set? Since the total experience of the results is ever so much smaller than the 69 Choose 5 current possibilities I would be very surprised if many of the individual numbers have result selection rates near the 1/69.
This is likely to be an interesting excercise.
I think the rule you state here "1 has a 9 percent chance of being a 1 and a 0 percent chance of being a 45" is because you are examing the ordered result reported in summaries.
If the order of balls drawn in a lottery like the PowerBall is in order as seen on TV , 23,7, 18,2,53 the summary reported in the data I have would be 2, 7, 18, 23, 53. So the 45 ball has a very small opportunity to be reported in the first postion of the ordered tuple.
So the question is are you concerned with combinations or permutations (without and with order)? The process you describe seems to describe a process that is somewhat permutation but using the probability of appearance in a combination.
I would suggest to start with a subset problem such as 10 balls and picking 2 where you can look at all of the possibilities and see results easier.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.