data have;
input ID STATE $ eff_date : mmddyy10.;
format eff_date mmddyy10.;
cards;
123 CA 10/18/2017
123 CA 10/18/2017
123 NY 3/25/2018
123 NY 3/25/2018
234 AZ 1/1/2018
234 AZ 7/18/2018
;
proc sort data=have out=_have;
by id state descending eff_date;
run;
data want;
set _have;
by id state descending eff_date;
if first.state;
run;
or
proc sort data=have out=_have;
by id state eff_date;
run;
data want;
set _have;
by id state eff_date;
if last.state;
run;
or
proc sql;
create table want as
select distinct *
from have
group by id,state
having eff_date=max(eff_date);
quit;
Which record do you want when the latest date is duplicated?
Please provide us a better and comprehensive sample of what you have and your required output for the sample
Assuming you means STATE and not CITY and that you prefer a record with a non missing STATE when there there is one but a missing STATE when it's the only one on the LAST eff_date :
data test;
input ID STATE $ eff_date :mmddyy.;
format eff_date yymmdd10.;
datalines;
123 CA 10/18/2017
123 CA 10/18/2017
123 NY 3/25/2018
123 NY 3/25/2018
234 AZ 1/1/2018
234 AZ 7/18/2018
234 . 7/18/2018
;
proc sort data=test out=last;
by descending eff_date descending state; run;
data want; set last(obs=1); run;
proc print; 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.