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)
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.