/* Richard A. DeVenezia * www.devenezia.com * * Temperature difference matrix * * On July 3, 2003 Ken Keung posed an interesting question to SAS-L Subject: A computation question Hello, I have a question. Here is a dataset with 6 variables. Let me explain the variables first. OBS : Observation number C1: Component 1 (dummy variable: 1="In the pot", and 0="NOT in the pot") C2: Component 2 (dummy variable: 1="In the pot", and 0="NOT in the pot") C3: Component 3 (dummy variable: 1="In the pot", and 0="NOT in the pot") HOW_MANY: How many components in the pot. TEMP : Temperature OBS C1 C2 C3 HOW_MANY TEMP 1 1 0 0 1 4 2 0 1 0 1 1 3 0 0 1 1 3 4 1 1 0 2 16 5 1 0 1 2 13 6 0 1 1 2 9 7 1 1 1 3 22 As you can see, all the combinations of 3 components are listed. If we put the Component 1 into a empty pot, then the temperature goes to 4 from 0. When Component 2 is added to the pot (so it has Component 1 and 2), the temperature increases to 16. The increment of temperature is 12 (=16 - 4), which is due to the addition of Component 2 to the existing pot. One thing to note is that the temperature always goes up when a component is added. I want to produce an output table like this. OBS C1 C2 C3 HOW_MANY 1 4 . . 1 2 . 1 . 1 3 . . 3 1 4 15 12 . 2 5 10 . 9 2 6 . 6 8 2 7 13 9 6 3 For clarification, consider C1 in OBS 7, its value is 13. 13 is temperature increase (from 9 to 22), when Component 1 is added to the pot when it already contained Component 2 and 3. ----- My challenge is that I have 20 components, NOT 3 as shown above. That means there are 1,048,575 observations (2 to the power of 20 minus 1) in the dataset. After approximately 20 hours (YES! hours) waiting, my computer (1.7GHZ and 512MB memory) couldn't produce the output. I know that I should not blame the computer. Anyway, I was able to obtain the sas output with 15 Components case in an hour. Would you kindly help me to code it more efficient way ? Thank you very much for your help in advance. -------------------------------------------------------------------------------- */ /* * Right away, the two state values, 0 and 1 of the variables C1-C20 * smelled of binary. Any attempt to deal with C1-C20 in a non binary sense * would be foolhardy. * * Ken states he has temperature data for all cases of c1-c20 * Let x = binary value represented by in/out state values found in c1-c20 * Thus T[x] is known for 0