# Vensim Help

 Navigation: Reference Guide > Functions > Logical Functions SAMPLE IF TRUE (condition, input,initial value) SAMPLE input IF condition is TRUE and then hold

Returns input when condition is true and otherwise remains constant.  The function initially holds constant at the stated initial value.  This function is useful for retaining information about a variable's behavior.

Restrictions: SAMPLE IF TRUE must directly follow the equal sign and not be followed by anything.  If you are using the Equation Editor, select Variable type Level and subtype Sample if True.

 Units: SAMPLE IF TRUE (dmnl, unit, unit ) --> unit

Units for the input and initial value must match and are returned.

NOTEThe variable defined by SAMPLE IF TRUE is like an Auxiliary in that it will change depending on the current value of the inputs.  However, the variable is also like a Level in that the value at the present time may depend on the values of variables at a previous time.  Vensim reports variables defined using SAMPLE IF TRUE as Auxiliaries.

The SAMPLE IF TRUE function allows you to use the same variable on the left and right side of an equation.  When the same variable appears on the right it is the previous value of the variable that is used.  For all other variables it is the current value of the variable that is used.

Examples

 max workforce = SAMPLE IF TRUE(Workforce > max workforce,
 workforce,workforce) {retains the maximum value of workforce}
 starting cash = SAMPLE IF TRUE(MODULO(Time,12)<.5,cash,cash)
 {retains the cash position at the beginning of the year throughout the year (Time in months)}

starting time = SAMPLE IF TRUE(:NOT: starting time :AND:

project is started,Time,0) {retains time at which project starts}

If you are using an integration technique other then Euler, the value of the output of the SAMPLE IF TRUE function will change within the integration step, though the reported value will always be computed on an even time step.  Thus if TIME STEP is 1 and using RK4 Auto integration project is started becomes non-zero at time 3.25, starting time will be reported as 4.0.  If any other variables use starting time they may receive a value of between 3.25 and 4.0 within the integration step.

Availability: Not PLE or PLE Plus.