How to print non-consecutive / consecutive dates from given set of dates?
Data x;
Input patid date mmddyy10.;
Datalines;
1001 02/01/10
1001 02/02/10
1001 02/03/10
1002 02/01/10
1002 02/03/10
1002 02/05/10
;
Run;
Can anyone explain the detailed logic step by step?
data want;
set x;
by patid;
flag = (not first.patid and date ne lag(date) + 1);
run;
This might be a good situation to use the DIF function, where dif(x) is equivalent to x - lag(x):
data want;
set have;
by patid;
if first.patid=0 and dif(date)=1 then consecutive='Y';
else consecutive='N';
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.