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;
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.