quick SAS v8 macro help

#1
hi,
i have a dataset=jen that contains 3 variables: subject, type, and
recdate1. i just want to see which subjects have 3 or more consective days of data.
I used this macro: (it runs and produces no output nor does it produce any errors in the log). can anyone see the problem? i feel like it has to do with my first line below defining my macro?? Thanks so much in advance!

%macro consecutivedays (subject, recdate1, indata=jen, numconday=3, oudata=out1);


proc sort data=&jen nodupkeys;
by &subject &recdate1;
run;

data one;
set &jen;
by &subject &recdate1;
tempdate=lag(&recdate1);
if first.&subject then tempdate=.;
retain cflag;
if first.&subject then cflag=1;
if &recdate1 ne tempdate+1 then cflag=cflag+1;
run;

data two(keep=&subject cflag consecutive);
set one;
by &subject cflag;
retain consecutive; if first.cflag then consecutive=0;
consecutive=consecutive+1;
if last.cflag and consecutive>=&numconday;
run;

data three;
merge one two(in=a);
by &subject cflag;
if a;
run;
proc sort data=three;
by &subject cflag &recdate1;
run;
data four;
set three;
by &subject cflag &recdate1;
retain firstdate;
if first.cflag then firstdate=&recdate1;
lasdate=&recdate1;
format lasdate firstdate date9.;
if last.cflag; run;

proc sort data=four(drop=cflag &recdate1 tempdate) out=&outdata;
run;
%mend consecutivedays;
 

Mean Joe

TS Contributor
#2
I don't think you want the line
if &recdate1 ne tempdate+1 then cflag=cflag+1;

Because if recdate1 is 2 days after tempdate, then you will increment cflag, even though the records are not on consecutive days.

data one;
set &jen;
by &subject &recdate1;
tempdate=lag(&recdate1);
if first.&subject then tempdate=.;
retain cflag;
if first.&subject then cflag=1;
if &recdate1 ne tempdate+1 then cflag=cflag+1;
run;