BookmarkSubscribeRSS Feed
Crubal
Quartz | Level 8

The table below lists each possibility for each variable 'A', 'B' and 'C', and the probability of that combination occurring. I already know all the probabilities.

Row # | A | B | C | Probability
============================================================
0 | ... | ... | ... | P0
------------------------------------------------------------
1 | ... | ... | ... | P1
------------------------------------------------------------
. | ... | . | . | .
------------------------------------------------------------
. | ... | . | . | .
------------------------------------------------------------
10 | ... | ... | ... | P10
------------------------------------------------------------



I would like to write an iteration within a combination of variables 'A', 'B' and 'C', start from Row = 0, keep increasing
for Row # = i. If P(Row >= i) * 300 - P(Row < i) * 600 > 0 do i = i+1; until P(Row >= i) * 300 - P(Row < i) * 600 <= 0 or i =10.

It will stop and output i for a combination of 'A', 'B' and 'C'. And i is what I need for a combination of (A / B / C). Which is regarded as 'Threshold' in my problem.

How could I write this kind of code since there are many combinations of variables 'A', 'B' and 'C'.

 

Example:

 

Row # | A | B | C | Probability
============================================================
0 | ... | ... | ... | 0.05
------------------------------------------------------------
1 | ... | ... | ... | 0.1
------------------------------------------------------------
2 | ... | ... | ... | 0.15
------------------------------------------------------------
3 | ... | ... | ... | 0.2
------------------------------------------------------------

4 | ... | ... | ... | 0.2
------------------------------------------------------------

...................................
10 | ... | ... | ... | 0.03
------------------------------------------------------------

 

When i = 0, P(Row >= 0) * 300 - P(Row < 0) * 600 = 1* 300 - 0* 600 = 300 > 0 Hence, i = 0+1 = 1

When i = 1, P(Row >= 1) * 300 - P(Row < 1) * 600 = 0.95* 300 - 0.05* 600 = 255 > 0 i = 1+1 = 2

When i = 2, P(Row >= 2) * 300 - P(Row < 2) * 600 = 0.85* 300 - 0.15* 600 = 165 > 0 i = 2+1 = 3

When i = 3, P(Row >= 3) * 300 - P(Row < 3) * 600 = 0.70* 300 - 0.30* 600 = 30 > 0 i = 3+1 = 4

When i = 4, P(Row >= 4) * 300 - P(Row < 4) * 600 = 0.50* 300 - 0.50* 600 = -150 < 0

we stop and output i =4 for this combination of 'A', 'B' and 'C'.

 

And, P(Row >= i) = 1- P(Row < i)

 

Thank you!

3 REPLIES 3
ballardw
Super User

It really would help to post the data values. Use a datastep generated from your data. Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.

 

When you say this for example:

 

When i = 3, P(Row >= 3) * 300 - P(Row < 3) * 600 = 0.70* 300 - 0.30* 600 = 30 > 0 i = 3+1 = 4

1) where does i come from at the begining? You don't mention a variable i in the description. Are you perhaps meaning two different things for i?

2) What does P(Row>=3) mean? Is that supposed to be a specific probability value or the sum/product/difference/other calculation involving all of the probabilites for row 3 through 10? If so provide the individual values  and how they are combined to get (I assume) a value of .70.

 

3) why does this: When i = 2, P(Count >= 2) * 300 - P(Row < 2) * 600 = 0.85* 300 - 0.15* 600 = 165 > 0 i = 2+1 = 3 use count?

 

I see a relation, I think, that  P(Row < 0) = (1- P(Row >= 0)). Does that relationship hold.

I am not sure what the actual values for the probability are an how they relate as there is not any example. example.

 

If all of these P(Row >= 0)  actually mean the value of the Probability variable that is being hidden behind P0 then your formula reduces to 900*Probability - 600

 

 

Crubal
Quartz | Level 8

Hi,

 

Sorry for making you confused. The content original post is gone with the example probability table.I just updated with my post so that probability can be seen. 

 

i means Row #, we start from Row # = 0, which means i starts at 0, and keep increasing to some threshold. 

 

 By the way, as you mentioned, P(Row < 0) = (1- P(Row >= 0)) always holds. 

 

And 'Count' is a typo, please regard it as row #, and I changed it as well. 

 

Thank you! 

 

 

ballardw
Super User

 P(Row >= 0) apparently means P0 + P1 + P2 + .. + P10.

As such I think this really needs to go to Proc IML as you are doing matrix manipulation. To do this out side of Proc IML I think is going to require a transpose, several arrays and likely another transpose to get into a useable output format.

 

And you really should show enought data for a least one use case in the form of a datastep, the desired result in the form of a datastep as well.

I'm not going to make a fake data set to try to write code against. You have the starting data set and it is very easy to transform a existing data set to datastep code. Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to connect to databases in SAS Viya

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.

Discussion stats
  • 3 replies
  • 661 views
  • 1 like
  • 2 in conversation