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;
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.