Hi @deengyn, This is helpful but need more answers. As a preliminary step, you can take my program for the first patient and add 1 or 2 more patients with the data that you currently HAVE. Next, let us also know what you would like to see as the end result of that dataset with DIFF generated. Let us keep this to convention and call it the WANT dataset. From what you have clarified in (2) above, I see that you may need more than one DIFF value. DIFF1 - from General Visit. DIFF2 from Initial Surgery. Finally, from (3) would you be able to add a sample patient to cover that scenario and how it would affect DIFF(s) values. You would also need to generate the WANT dataset with code similar to the one I provided for generating the HAVE dataset above. One last piece. The dataset (picture) from your first post does NOT represent the code that you provided later. If that is the result of the sort below then for Patient 51, the first SERV_DATE value would be 25SEP2017. *Formatting; proc sort data = plbr out = plb_sorted; by pid serv_date rec_num ; run;
... View more