@andreas_lds
Thank you for your response. When I use the fix below, I am getting the correct logic but not the correct result:
Episode should show 1,2,3,3,3, Here it is starting at 0.
I tried changing the initial value of episode to 1,
rsubmit;
data check1;
set check;
by FDS;/*First day of Service*/
if first.patid then do;
difference = 0;
episode = 1;
end;
if difference > 180 then episode +1;
run;
endrsubmit;
But even then its showing the same results.