I want to enumerate over groups in SAS. I have the following data set and have attached 2 possible scenarios that I am looking for. locationnurseunitcodedesc transaction_start_dt_tm transaction_stop_dt_tm THIS IS WHAT I WANT BETTER YET
STATION 1 8/31/16 10:33 10/3/16 9:54 1 1
STATION 2 10/3/16 9:54 10/3/16 9:54 1 1
STATION 3 10/3/16 9:54 10/3/16 9:54 1 0
STATION 3 10/3/16 9:54 10/3/16 9:54 2 0
STATION 3 10/3/16 9:54 10/3/16 12:11 3 1
STATION 4 10/3/16 12:11 10/3/16 18:39 1 1
STATION 3 10/3/16 18:39 10/4/16 12:26 1 0
STATION 3 10/4/16 12:26 10/13/16 10:43 2 0
STATION 3 10/13/16 10:43 10/13/16 10:43 3 0
STATION 3 10/13/16 10:43 10/4/16 12:25 4 1
When I use the following code the seq number never goes above 2
data wantONETWO;
set WANTONE;
RETAIN SEQ 0;
SEQ=1;
PRIOR_UNIT = LAG(locationnurseunitcodedesc);
IF locationnurseunitcodedesc = PRIOR_UNIT THEN DO;
SEQ + 1;
END;
run;
Best
Aaron