BookmarkSubscribeRSS Feed
madhu
Calcite | Level 5
I have a situation like below.

patno visitdate
101 10-feb-09
101 11-feb-09
101 14-feb-09
101 15-feb-09

In the above example dates 12-feb and 13-feb are missing. I want to identify patients where atleast 2 consecutive dates are missing.

Thanks in advance.
3 REPLIES 3
Flip
Fluorite | Level 6
Try something like where not first.patno and (visitdate - lag(visitdate) >2);
data_null__
Jade | Level 19
Check out DIF function:
[pre]
Returns differences between the argument and its nth lag
[/pre]

[pre]
data pats;
input patno:$3. visitdate:date.;
cards;
101 10-feb-09
101 11-feb-09
101 14-feb-09
101 15-feb-09
102 10-feb-09
102 13-feb-09
102 14-feb-09
102 16-feb-09
;;;;
run;
data pats(keep=patno);
f = 0;
do until(last.patno);
set pats;
by patno;
d = ifn(not first.patno,dif(visitDate),0);
if not f and d ge 2 then do;
output;
f=1;
end;
end;
run;
proc print;
run;[/pre]
Patrick
Opal | Level 21
This approach following Flip's suggestion:

data pats;
input patno:$3. visitdate:date.;
cards;
101 10-feb-09
101 11-feb-09
101 14-feb-09
101 15-feb-09
102 10-feb-09
102 13-feb-09
102 14-feb-09
102 16-feb-09
103 16-feb-09
103 17-feb-09
103 19-feb-09
;;;;
run;

data want(keep=patno);
set pats;
by patno;
retain flag 0;
if visitdate-lag(visitdate)>2 then
if not first.patno then flag=1;
if last.patno and flag=1 then
do;
output;
flag=0;
end;
run;

proc print data=want;
run;

HTH
Patrick
What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1556 views
  • 0 likes
  • 4 in conversation