DIF updates a queue of differences. If you only occasionally execute DIF then the sequence of differences are applied only to the corresponding observations. This program accommodates that property:
DATA EM_LIST_W_DAYS;
set WORK.EM_LIST;
by ClaimNum ParticipantID;
dif=ifn(first.paarticipantid,0,dix(tx_dos));
run;
Two points:
Using "by cliaminum participantid;". The first. and last. indicators are hierarchical. All instances of first.claimnum=1 are subsets of the instances in which first.participantid=1. And (less petinent in your case) every time first.claimnum=1 all the by-variables to its right will have first. indicators set to 1.
The IFN function evaluates both outcomes (the 2nd and 3rd arguments), regardless of the results of the first argument. As a result the DIF function is updated with every observation, even though it is not always assigned to the result variable.
... View more