I cannot figure out why the dif function is going back 2 rows in the second observation. It works for the first observation and all subsequent observations. In the 2nd and fourth row the dif function is not calculating the value I would like. I am sure that my lack of understanding of first is the culprit, but I can't figure it out. (Row 2 difference should be 0, Row 4 difference should be 1) Any help is greatly appreciated (I use SAS EG 7.1, SAS 9.4). Output data ClaimNum Participant_Name TX_DOS difference CLAIM1 NAME1 9/13/2016 0 CLAIM1 NAME1 9/13/2016 . CLAIM2 NAME2 8/25/2015 0 CLAIM2 NAME2 8/26/2015 -384 CLAIM2 NAME2 8/27/2015 1 SAS Code DATA EM_LIST_W_DAYS;
set WORK.EM_LIST;
by ClaimNum ParticipantID;
if first.ClaimNum and first.ParticipantID then
difference = 0;
else if first.ClaimNum=0 and first.ParticipantID=1 then
difference = 0;
else if first.ClaimNum=0 and first.ParticipantID=0 then
difference = DIF(TX_DOS);
run;
... View more