Hi Team,
I need help for below scenario.
All dated will be in ascending order and if any date is smaller than its previous date then that is odd and need to be filter out.
I applied lag function but it is getting applied on entire variable not on group if 1 and 2 separately.
data test1;
input id date$12.;
datalines;
1 01JAN2010
1 04JAN2010
1 08JAN2010
1 07JAN2010
1 11JAN2010
2 05JAN2010
2 06JAN2010
2 04JAN2010
2 07JAN2010
2 10JAN2010
;
RUN;
Expected output:
1 07JAN2010
2 04JAN2010
Before doing anything else, convert the strings to SAS dates by using the INPUT function with the DATE9. informat.
Then it's easy:
data want;
set test1;
by id;
if date lt lag(date) and not first.id;
run;
Before doing anything else, convert the strings to SAS dates by using the INPUT function with the DATE9. informat.
Then it's easy:
data want;
set test1;
by id;
if date lt lag(date) and not first.id;
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.