I have a data set like this :
ID NAME BEGIN END
345 CARL 16MAR2017 31MAR2017
345 CARL 03APR2017 30APR2017
120 ROSA 01JAN2017 14FEB2017
120 ROSA 02DEC2016 31DEC2016
How can I delete occurence but taking the most recent date ? I mean get some thing like this :
ID NAME BEGIN END
345 CARL 03APR2017 30APR2017
120 ROSA 01JAN2017 14FEB2017
SAS can handle this easily enough, but the solution in part depends on whether your BEGIN and END variables are valid SAS dates vs. whether they are character strings. PROC CONTENTS will tell you that. If they are valid SAS dates:
proc sort data=have;
by id begin;
run;
data want;
set have;
by id begin;
if last.id;
run;
If your dates are actually character strings, does "JANV" actually appear in your data, or is that supposed to be "JAN"? If there are invalid dates (which would include "JANV") they would need to be fixed first. Then ...
data want;
set have;
begin_sasdate = input(begin, date9.);
end_sasdate = input(end, date9.);
format begin_sasdate end_sasdate date9.;
run;
proc sort data=want;
by id begin_sasdate;
run;
data want;
set want;
by id begin_sasdate;
if last.id;
run;
It's the same approach, but this approach requires that your data contain SAS dates, not character strings.
SAS can handle this easily enough, but the solution in part depends on whether your BEGIN and END variables are valid SAS dates vs. whether they are character strings. PROC CONTENTS will tell you that. If they are valid SAS dates:
proc sort data=have;
by id begin;
run;
data want;
set have;
by id begin;
if last.id;
run;
If your dates are actually character strings, does "JANV" actually appear in your data, or is that supposed to be "JAN"? If there are invalid dates (which would include "JANV") they would need to be fixed first. Then ...
data want;
set have;
begin_sasdate = input(begin, date9.);
end_sasdate = input(end, date9.);
format begin_sasdate end_sasdate date9.;
run;
proc sort data=want;
by id begin_sasdate;
run;
data want;
set want;
by id begin_sasdate;
if last.id;
run;
It's the same approach, but this approach requires that your data contain SAS dates, not character strings.
yes its valid date (I edit the topic, its JAN instead of JANV)
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.