Hi,
Forthe following table X, for each combination of variable 'A', 'B' and 'C', there are 'Count' from 0 to 10. 'Probability' means the probability for 'Count' equals to that value.
Where P1 = Probability(Count = 1) and P0 + P1 + ... + P10 = 1.
P0, P1, ..., P10 is known.
A B C Count Probability
... ... ... 0 P0
... ... ... 1 P1
. . . . .
. . . . .
... ,,, ,,, 10 P10
I would like to write an iteration within a combination of variables 'A', 'B' and 'C', start frpm Count = 0, keep increasing
for count = i. If P(Count >= i) * 300 - P(Count >= i) * 600 > 0 do i = i+1; until P(Count >= i) * 300 - P(Count >= i) * 600 <= 0 or i =10. It will stop and output i for a combination of 'A', 'B' and 'C'.
What I need is the number of i, which is regarded as a threshold number in my case (combination of A, B and C)
How could I write this kind of code since there are many combinations of variables 'A', 'B' and 'C'.
As an example:
A B C Count Probability
... ... ... 0 0.05
... ... ... 1 0.10
. . . 2 0.15
. . . 3 0.20
. . . 4 0.20
. . . . .
. . . . .
... ,,, ,,, 10 1
Example:
When i = 0, P(Count >= 0) * 300 - P(Count < 0) * 600 = 1* 300 - 0* 600 = 300 > 0 Hence, i = 0+1 = 1
When i = 1, P(Count >= 1) * 300 - P(Count < 1) * 600 = 0.95* 300 - 0.05* 600 = 255 > 0 i = 1+1 = 2
When i = 2, P(Count >= 2) * 300 - P(Count < 2) * 600 = 0.85* 300 - 0.15* 600 = 165 > 0 i = 2+1 = 3
When i = 3, P(Count >= 3) * 300 - P(Count < 3) * 600 = 0.70* 300 - 0.30* 600 = 30 > 0 i = 3+1 = 4
When i = 4, P(Count >= 4) * 300 - P(Count < 4) * 600 = 0.50* 300 - 0.50* 600 = -150 < 0 we stop and output i =4 for this combination of 'A', 'B' and 'C'.
Thank you!
It really helps to provide at least a small sample of starting data, say one combination of A B C and the other variables and then what the desired output for that sample data would be.
But in view of your other post about the news vendor problem I suspect that Proc IML may be more conducive and the whole question maybe belongs in either SAS/IML Softaware and Matrix Computations or the Mathmatical Optimization, Discrete-Event Simulation, and OR part of the forum.
Thank you! That's a good idea, I changed it and made a small example. I will look at PROC IML as well. Thanks!
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!
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.