Quantcast
Channel: Statistics Help @ Talk Stats Forum - SAS
Viewing all articles
Browse latest Browse all 310

Lag Function with dates

$
0
0
Hi I have a table with patients and their visit history. I created this table by combining list of potential patient table with list of patient that went to fracture clinic. Doctor wanted to know from the potential patient who came back for fracture clinic visit. My problem is with my lag function.

Here is my lag function:

DATA mergeFracWithPotent_lag;
SET mergeFracWithPotent;
IF chartnumber = LAG(chartnumber) and area ne lag(area) then ReturnFractVisit = 'yes';
else ReturnFractVisit = 'No';
RUN;

Here is where the problem is:

ChartNumber RegNumber visit_id reg_datetime Area returnFractVisit
123456 234623 34 01APR2013:13:22:00 (blank) NO
123456 326452 -1 16MAY2013:14:02:00 Fracture yes
123456 123112 12 18May2013:23:22:00 (blank) YES
123456 443221 -1 22MAY2013:11:22:00 Fracture Yes

I don't mind for returnfractvisit to have three yes I could just do a distinct count on chartnumber to get number of those return for fracture visit. My problem is the datetime comparision I tried putting it into the code like reg_datetime<lag(datetime) then I get all "no" for returnfractvisit. Also samething if I put lag(area) = 'Fracture'. I would get all No for the returnFractVisit.

Basically I am more concerned if the datetime was the same then it should not be counted as a return visit and if it is putting yes at the correct spots.

Viewing all articles
Browse latest Browse all 310

Trending Articles