So my code is
data readms2;
set readms;
PRV_DC_DT = lag(DC_DT);
if _N_=1 then PRV_DC_DT = DC_DT;
format PRV_DC_DT date9.;
PRV_DC_REASON = lag(PRIM_DSCH_REASON);
if _N_=1 then PRV_DC_REASON = PRIM_DSCH_REASON;
run;
I have a unique client ID...
NUM_ADM =0 is the first admission NUM_ADM=1 is a readmission. Essentially when NUM_ADM=0, PRV_DC_DT and PRV_DC_REASON should be missing because they are the first admission so there is not another relevant record to lag from... I'm instead incorrectly getting lagged values from other client IDs when NUM_ADM=0...
What am I missing here... what do I need to make to my code to have the lagged values start on the NUM_ADM=1 record? Thanks in advance.
Resulting, incorrect table is:
![Capture.PNG Capture.PNG](https://communities.sas.com/t5/image/serverpage/image-id/35327iB182A8EEC0832640/image-size/large?v=v2&px=999)