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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.