Thank You very much for the detailed answer - much appreciated! However, I'm still confused as to why first setting AND then using the IF operator in a second data step works fine while when setting and using IF in the same step gives the wrong result? I'm assuming it's something to do with the initialisation of the variable "index". Also, if none of the conditions are met, I thought that it will just evaluate "index" as missing as it simply doesn't have anything assigned - clearly, however, in some cases it sets it to missing (when 2 data steps are used) and sometimes it "carries over" the previous value (when 1 data step is used).
... View more