# Vensim Help

 Navigation: Reference Guide > Functions > Dynamic Functions SHIFT IF TRUE(var,cond,size,accum,inval) SHIFT elements of var IF cond is TRUE

Shifts size elements of var when cond is true.  If accum is non-zero then the second to last element of var is added to the last element, otherwise the second to last element replaces the last element.  Shifting occurs relative to the rightmost subscript of var.  If a shift does occur, then the first element of the rightmost subscript of var is replaced with inval. SHIFT IF TRUE returns the amount that has been removed from the last element of var.  If accum is non-zero then SHIFT IF TRUE always returns 0.

SHIFT IF TRUE is useful for managing aging chains or cohorts.  The most common application would be to populations in which maintaining an accurate age distribution is important.

Units: SHIFT IF TRUE(units,dmnl,dmnl,dmnl,units) --> units

NOTE Be very careful when specifying the size argument to SHIFT IF TRUE.  IF this argument is too big it can change other variables.  In general, since SHIFT IF TRUE modifies the values of the variable it is called with, it should be used with care.

NOTE Be sure that the subscript order of var  is set up so that the final subscript is the one to be shifted over.

Example

age : IN VITRO,(AGE 1-AGE 65) ~~|

ageh :(AGE 1-AGE 65) ~~|

country : usa,mexico ~~|

gender : male, female ~~|

Population[country,gender,IN VITRO]=
INTEG(conceptions[country]-deaths[country,gender,IN VITRO],

 INIT POP[country,gender,IN VITRO]) ~~|

Population[country,gender,ageh]=INTEG(-deaths[country,gender,ageh],

INIT POP[country,gender,ageh]) ~Person~|

a[country,gender]=SHIFT IF TRUE(Population[country,gender,IN VITRO],

MODULO(TIME,1)=0,ELMCOUNT(AGE),1,0)~Person~~:SUP|

Note that for all but IN VITRO, Population has no inflow. Population in cohorts beyond the first is increased by the aging process implicit in SHIFT IF TRUE.

Availability: Professional and DSS only.

Sample model: SHIFT IF TRUE.mdl in FunctionExamples