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;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: