17Jun16

The scenario is that you want a two-code variable where c1=under a particular threshold, and c2=same as or over the threshold. The problem is: what if the threshold value is dynamic, that is, not known at scripting time? The solution is to run a table to get the threshold, and then plug that value into the construction.

This example gets the code median from FAVRAT_1, constructs a new variable for under/over the median, and then verifies the construction by a table.

```
#include c:rubyRubyUtilitiesLibrary.vbs
#include c:rubyRubyVariablesLibrary.vbs
#include c:rubyRubyReportsLibrary.vbs
Sub Main()
Initialise()
ClearRAM
top = "Count"
filt = ""
wght = ""
'' get the median
GenTab "FavRat_1 Median", top, "FAVRAT_1", filt, wght
median = rep.GetRawStat("Column", "cme", 0, 0) '' return cme for column at cell 0,0 = 7
'MsgBox median '' debug
'' construct under/over
DefCon "FAVRAT_1_UO", "Favourability Rating Segment by Median"
AddItem 1, "sum_FAVRAT_1(*)<" & median, "Under"
AddItem 2, "sum_FAVRAT_1(*)>=" & median, "Equal or Over"
ConClose
Construct "FAVRAT_1_UO"
'' confirm by a comparison table
side = "FAVRAT_1(#sum#(1/" & median-1 & ");#sum#(" & median & "/10);cme),FAVRAT_1_UO"
GenTab "FavRat_1 Median UO Check", top, side, filt, wght
Cleanup()
End Sub
```

The final table is: