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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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