What you really want is to always update the queue, but conditionally return the lag3 value. So change
if mod(day, 2)=0 then three_days_ago_even=lag3(day);
to
three_days_ago_even=ifn(mod(day, 2)=0,lag3(day),.);
Unlike the IF statement, the IFN function always calculates both possible outcomes, and then choose one based on the IF condition in the first parameter. This means the LAG3 queue is always updated, but not always returned.
For more on this, take a look at Leads and Lags: Static and Dynamic Queues in the SAS® DATA STEP
... View more